Files
empidee/src/commands/queue/prio.rs
h7x4 07e1c76aa9
Some checks failed
Build and test / check (push) Failing after 43s
Build and test / build (push) Successful in 1m2s
Build and test / docs (push) Successful in 1m12s
Build and test / test (push) Successful in 1m44s
commands: parse to Self::Request
2025-12-05 22:00:11 +09:00

50 lines
1.4 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, RequestParserError, ResponseParserError},
common::types::{Priority, WindowRange},
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
};
pub struct Prio;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PrioRequest {
pub prio: Priority,
pub window: WindowRange,
}
impl Command for Prio {
type Request = PrioRequest;
type Response = ();
const COMMAND: &'static str = "prio";
fn serialize_request(&self, request: Self::Request) -> String {
format!("{} {} {}", Self::COMMAND, request.prio, request.window)
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> Result<Self::Request, RequestParserError> {
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let prio = prio
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, prio.to_string()))?;
let window = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let window = window
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, window.to_string()))?;
debug_assert!(parts.next().is_none());
Ok(PrioRequest { prio, window })
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
debug_assert!(parts.is_empty());
Ok(())
}
}