Files
empidee/src/commands/music_database/searchaddpl.rs
h7x4 ed7f9a6917
Some checks failed
Build and test / build (push) Successful in 1m1s
Build and test / check (push) Failing after 1m0s
Build and test / test (push) Successful in 1m37s
Build and test / docs (push) Successful in 1m16s
commands: implement some more response parsers
2025-02-23 16:41:15 +01:00

69 lines
2.0 KiB
Rust

use crate::{
commands::{
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError,
},
filter::parse_filter,
};
pub struct SearchAddPl;
impl Command for SearchAddPl {
type Response = ();
const COMMAND: &'static str = "searchaddpl";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let playlist_name = parts
.next()
.ok_or(RequestParserError::UnexpectedEOF)?
.to_string();
let filter = parse_filter(&mut parts)?;
let mut sort_or_window_or_position = parts.next();
let mut sort = None;
if let Some("sort") = sort_or_window_or_position {
sort = Some(
parts
.next()
.ok_or(RequestParserError::UnexpectedEOF)?
.to_string(),
);
sort_or_window_or_position = parts.next();
}
let mut window = None;
if let Some("window") = sort_or_window_or_position {
let w = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
window = Some(
w.parse()
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))?,
);
sort_or_window_or_position = parts.next();
}
let mut position = None;
if let Some("position") = sort_or_window_or_position {
let p = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
position = Some(
p.parse()
.map_err(|_| RequestParserError::SyntaxError(0, p.to_string()))?,
);
}
debug_assert!(parts.next().is_none());
Ok((
Request::SearchAddPl(playlist_name, filter, sort, window, position),
"",
))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty());
Ok(())
}
}