Lines
0 %
Functions
use crate::{
commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
},
common::PlaylistName,
};
pub struct ListPlaylist;
pub type ListPlaylistResponse = Vec<PlaylistName>;
impl Command for ListPlaylist {
type Response = ListPlaylistResponse;
const COMMAND: &'static str = "listplaylist";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let name = name
.parse::<PlaylistName>()
.map_err(|_| RequestParserError::SyntaxError(0, name.to_owned()))?;
let range = parts
.next()
.map(|s| {
s.parse()
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))
})
.transpose()?;
debug_assert!(parts.next().is_none());
Ok((Request::ListPlaylist(name.to_string(), range), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into();
parts
.into_iter()
.map(|(name, value)| {
debug_assert_eq!(name, "file");
match value {
GenericResponseValue::Text(value) => Ok(value.to_string()),
GenericResponseValue::Binary(_) => Err(
ResponseParserError::UnexpectedPropertyType("file", "Binary"),
),
.collect::<Result<Vec<_>, _>>()