Lines
0 %
Functions
use crate::{
commands::{CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
};
pub struct RandomRequest(bool);
impl RandomRequest {
pub fn new(state: bool) -> Self {
Self(state)
}
impl CommandRequest for RandomRequest {
type Response = RandomResponse;
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);