Files
empidee/src/commands/playback_options/random.rs
T
oysteikt cf09865b02 commands: remove toplevel Request/Response enums
This also exposes all the command types as public API
2026-06-21 14:41:56 +09:00

52 lines
1.3 KiB
Rust

use crate::{
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
};
pub struct Random;
pub struct RandomRequest(bool);
impl RandomRequest {
pub fn new(state: bool) -> Self {
Self(state)
}
}
impl CommandRequest for RandomRequest {
const COMMAND: &'static str = "random";
const MIN_ARGS: u32 = 1;
const MAX_ARGS: Option<u32> = Some(1);
fn serialize(&self) -> String {
let state = if self.0 { "1" } else { "0" };
format!("{} {}\n", Self::COMMAND, state)
}
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let state = match parts.next() {
Some("0") => false,
Some("1") => true,
Some(s) => {
return Err(RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "bool",
raw_input: s.to_owned(),
});
}
None => return Err(Self::missing_arguments_error(0)),
};
Self::throw_if_too_many_arguments(parts)?;
Ok(RandomRequest(state))
}
}
empty_command_response!(Random);
impl Command for Random {
type Request = RandomRequest;
type Response = RandomResponse;
}