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

            
6
pub struct ListPartitions;
7

            
8
pub type ListPartitionsResponse = Vec<String>;
9

            
10
impl Command for ListPartitions {
11
    type Response = ListPartitionsResponse;
12
    const COMMAND: &'static str = "listpartitions";
13

            
14
    fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
15
        debug_assert!(parts.next().is_none());
16
        Ok((Request::ListPartitions, ""))
17
    }
18

            
19
    fn parse_response(
20
        parts: ResponseAttributes<'_>,
21
    ) -> Result<Self::Response, ResponseParserError> {
22
        let parts: Vec<_> = parts.into();
23

            
24
        let mut partitions = Vec::with_capacity(parts.len());
25
        for (key, value) in parts.into_iter() {
26
            debug_assert_eq!(key, "partition");
27

            
28
            let partition = match value {
29
                GenericResponseValue::Text(name) => name.to_string(),
30
                GenericResponseValue::Binary(_) => {
31
                    return Err(ResponseParserError::UnexpectedPropertyType(
32
                        "partition",
33
                        "Binary",
34
                    ))
35
                }
36
            };
37

            
38
            partitions.push(partition);
39
        }
40

            
41
        Ok(partitions)
42
    }
43
}