41 lines
1.0 KiB
Rust
41 lines
1.0 KiB
Rust
use crate::{
|
|
commands::{
|
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
|
ResponseParserError,
|
|
},
|
|
common::SongPosition,
|
|
};
|
|
|
|
pub struct Add;
|
|
|
|
impl Command for Add {
|
|
type Response = ();
|
|
const COMMAND: &'static str = "add";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
let uri = match parts.next() {
|
|
Some(s) => s,
|
|
None => return Err(RequestParserError::UnexpectedEOF),
|
|
};
|
|
|
|
let position = match parts.next() {
|
|
Some(s) => Some(
|
|
s.parse::<SongPosition>()
|
|
.map_err(|_| RequestParserError::SyntaxError(1, s.to_owned()))?,
|
|
),
|
|
None => None,
|
|
};
|
|
|
|
debug_assert!(parts.next().is_none());
|
|
|
|
Ok((Request::Add(uri.to_string(), position), ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError> {
|
|
debug_assert!(parts.is_empty());
|
|
Ok(())
|
|
}
|
|
}
|