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