Files
empidee/src/commands/queue/prio.rs
h7x4 7ec268094d
All checks were successful
Build and test / check (push) Successful in 58s
Build and test / build (push) Successful in 1m9s
Build and test / docs (push) Successful in 1m11s
Build and test / test (push) Successful in 2m26s
commands: store SubtypeParserError expected type as &str
2025-12-08 17:48:44 +09:00

68 lines
1.9 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
types::{Priority, WindowRange},
};
pub struct Prio;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrioRequest {
pub prio: Priority,
pub window: WindowRange,
}
impl CommandRequest for PrioRequest {
const COMMAND: &'static str = "prio";
const MIN_ARGS: u32 = 2;
const MAX_ARGS: Option<u32> = Some(2);
fn into_request_enum(self) -> crate::Request {
crate::Request::Prio(self.prio, self.window)
}
fn from_request_enum(request: crate::Request) -> Option<Self> {
match request {
crate::Request::Prio(prio, window) => Some(PrioRequest { prio, window }),
_ => None,
}
}
fn serialize(&self) -> String {
format!("{} {} {}\n", Self::COMMAND, self.prio, self.window)
}
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let prio = parts.next().ok_or(Self::missing_arguments_error(0))?;
let prio = prio
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "Priority",
raw_input: prio.to_string(),
})?;
let window = parts.next().ok_or(Self::missing_arguments_error(1))?;
let window = window
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 1,
expected_type: "WindowRange",
raw_input: window.to_string(),
})?;
Self::throw_if_too_many_arguments(parts)?;
Ok(PrioRequest { prio, window })
}
}
empty_command_response!(Prio);
impl Command for Prio {
type Request = PrioRequest;
type Response = PrioResponse;
}