37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use crate::{
|
|
Request,
|
|
commands::{
|
|
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
|
},
|
|
};
|
|
|
|
pub struct Swap;
|
|
|
|
impl Command for Swap {
|
|
type Response = ();
|
|
const COMMAND: &'static str = "swap";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> 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<Self::Response, ResponseParserError> {
|
|
debug_assert!(parts.is_empty());
|
|
Ok(())
|
|
}
|
|
}
|