1
use std::str::FromStr;
2

            
3
use crate::{
4
    commands::{
5
        Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
6
        ResponseParserError,
7
    },
8
    request::VolumeValue,
9
};
10

            
11
pub struct SetVol;
12

            
13
impl Command for SetVol {
14
    type Response = ();
15
    const COMMAND: &'static str = "setvol";
16

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

            
24
        debug_assert!(parts.next().is_none());
25

            
26
        Ok((Request::SetVol(volume), ""))
27
    }
28

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