1
use crate::commands::{
2
    Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
3
    ResponseParserError,
4
};
5

            
6
pub struct Save;
7

            
8
impl Command for Save {
9
    type Response = ();
10
    const COMMAND: &'static str = "save";
11

            
12
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
13
        let playlist_name = parts
14
            .next()
15
            .ok_or(RequestParserError::UnexpectedEOF)?
16
            .to_string();
17

            
18
        let mode = parts
19
            .next()
20
            .map(|m| {
21
                m.parse()
22
                    .map_err(|_| RequestParserError::SyntaxError(0, m.to_string()))
23
            })
24
            .transpose()?;
25

            
26
        debug_assert!(parts.next().is_none());
27

            
28
        Ok((Request::Save(playlist_name, mode), ""))
29
    }
30

            
31
    fn parse_response(
32
        parts: ResponseAttributes<'_>,
33
    ) -> Result<Self::Response, ResponseParserError> {
34
        debug_assert!(parts.is_empty());
35
        Ok(())
36
    }
37
}