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

            
6
pub struct StickerNames;
7

            
8
pub type StickerNamesResponse = Vec<String>;
9

            
10
impl Command for StickerNames {
11
    type Response = StickerNamesResponse;
12
    const COMMAND: &'static str = "stickernames";
13

            
14
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
15
        debug_assert!(parts.next().is_none());
16

            
17
        Ok((Request::StickerNames, ""))
18
    }
19

            
20
    fn parse_response(
21
        parts: ResponseAttributes<'_>,
22
    ) -> Result<Self::Response, ResponseParserError> {
23
        debug_assert!(parts.0.iter().all(|(k, _)| *k == "name"));
24

            
25
        let list = parts
26
            .0
27
            .into_iter()
28
            .map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
29
            .collect::<Result<Vec<_>, ResponseParserError>>()?;
30

            
31
        Ok(list)
32
    }
33
}