1
use crate::commands::{
2
    Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
3
    expect_property_type,
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
            let partition = expect_property_type!(Some(value), "partition", Text).to_string();
28
            partitions.push(partition);
29
        }
30

            
31
        Ok(partitions)
32
    }
33
}