use serde::{Deserialize, Serialize}; use crate::{ Request, commands::{ Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError, }, common::{Version, WindowRange}, }; pub struct PlChanges; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PlChangesRequest { pub version: Version, pub window: Option, } impl Command for PlChanges { type Request = PlChangesRequest; type Response = (); const COMMAND: &'static str = "plchanges"; fn serialize_request(&self, request: Self::Request) -> String { match request.window { Some(window) => format!("{} {} {}", Self::COMMAND, request.version, window), None => format!("{} {}", Self::COMMAND, request.version), } } fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?; let version = version .parse() .map_err(|_| RequestParserError::SyntaxError(0, version.to_string()))?; let window = parts .next() .map(|w| { w.parse() .map_err(|_| RequestParserError::SyntaxError(0, w.to_string())) }) .transpose()?; debug_assert!(parts.next().is_none()); Ok((Request::PlChanges(version, window), "")) } fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { unimplemented!() } }