Lines
0 %
Functions
use crate::{
commands::{CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
};
pub struct PauseRequest(Option<bool>);
impl PauseRequest {
pub fn new(state: Option<bool>) -> Self {
PauseRequest(state)
}
impl CommandRequest for PauseRequest {
type Response = PauseResponse;
const COMMAND: &'static str = "pause";
const MIN_ARGS: u32 = 0;
const MAX_ARGS: Option<u32> = Some(1);
fn serialize(&self) -> String {
match self.0 {
Some(true) => format!("{} 1\n", Self::COMMAND),
Some(false) => format!("{} 0\n", Self::COMMAND),
None => Self::COMMAND.to_string() + "\n",
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let result = match parts.next() {
Some("0") => Ok(Some(false)),
Some("1") => Ok(Some(true)),
Some(s) => Err(RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "Option<bool>",
raw_input: s.to_owned(),
}),
None => Ok(None),
Self::throw_if_too_many_arguments(parts)?;
result.map(PauseRequest)
empty_command_response!(Pause);