Lines
0 %
Functions
use std::collections::HashMap;
use crate::commands::{
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, get_and_parse_property,
};
pub struct PlaylistLength;
pub struct PlaylistLengthResponse {
pub songs: u64,
pub playtime: u64,
}
impl Command for PlaylistLength {
type Response = PlaylistLengthResponse;
const COMMAND: &'static str = "playlistlength";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let playlist_name = parts
.next()
.ok_or(RequestParserError::UnexpectedEOF)?
.to_string();
debug_assert!(parts.next().is_none());
Ok((Request::PlaylistLength(playlist_name), ""))
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: HashMap<_, _> = parts.into();
let songs = get_and_parse_property!(parts, "songs", Text);
let playtime = get_and_parse_property!(parts, "playtime", Text);
Ok(PlaylistLengthResponse { songs, playtime })