1
use crate::{
2
    commands::{
3
        Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
4
        ResponseParserError,
5
    },
6
    common::{SongId, TimeWithFractions},
7
};
8

            
9
pub struct SeekId;
10

            
11
impl Command for SeekId {
12
    type Response = ();
13
    const COMMAND: &'static str = "seekid";
14

            
15
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
16
        let songid = match parts.next() {
17
            Some(s) => s
18
                .parse::<SongId>()
19
                .map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
20
            None => return Err(RequestParserError::UnexpectedEOF),
21
        };
22

            
23
        let time = match parts.next() {
24
            Some(t) => t
25
                .parse::<TimeWithFractions>()
26
                .map_err(|_| RequestParserError::SyntaxError(0, t.to_owned()))?,
27
            None => return Err(RequestParserError::UnexpectedEOF),
28
        };
29

            
30
        debug_assert!(parts.next().is_none());
31

            
32
        Ok((Request::SeekId(songid, time), ""))
33
    }
34

            
35
    fn parse_response(
36
        parts: ResponseAttributes<'_>,
37
    ) -> Result<Self::Response, ResponseParserError> {
38
        debug_assert!(parts.is_empty());
39
        Ok(())
40
    }
41
}