34 lines
1.0 KiB
Rust
34 lines
1.0 KiB
Rust
use crate::commands::{
|
|
expect_property_type, Command, Request, RequestParserResult, ResponseAttributes,
|
|
ResponseParserError,
|
|
};
|
|
|
|
pub struct ListPartitions;
|
|
|
|
pub type ListPartitionsResponse = Vec<String>;
|
|
|
|
impl Command for ListPartitions {
|
|
type Response = ListPartitionsResponse;
|
|
const COMMAND: &'static str = "listpartitions";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
debug_assert!(parts.next().is_none());
|
|
Ok((Request::ListPartitions, ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError> {
|
|
let parts: Vec<_> = parts.into();
|
|
|
|
let mut partitions = Vec::with_capacity(parts.len());
|
|
for (key, value) in parts.into_iter() {
|
|
debug_assert_eq!(key, "partition");
|
|
let partition = expect_property_type!(Some(value), "partition", Text).to_string();
|
|
partitions.push(partition);
|
|
}
|
|
|
|
Ok(partitions)
|
|
}
|
|
}
|