Files
empidee/src/commands/queue/shuffle.rs

46 lines
1.2 KiB
Rust

use crate::{
Request,
request_tokenizer::RequestTokenizer,
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
common::OneOrRange,
};
pub struct Shuffle;
impl Command for Shuffle {
type Request = Option<OneOrRange>;
type Response = ();
const COMMAND: &'static str = "shuffle";
fn serialize_request(&self, request: Self::Request) -> String {
match request {
Some(range) => format!("{} {}", Self::COMMAND, range),
None => Self::COMMAND.to_string(),
}
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let range = parts
.next()
.map(|range| {
range
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, range.to_string()))
})
.transpose()?;
debug_assert!(parts.next().is_none());
Ok((Request::Shuffle(range), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
debug_assert!(parts.is_empty());
Ok(())
}
}