Files
empidee/src/commands/partition_commands/listpartitions.rs
h7x4 33ff376c91
Some checks failed
Build and test / build (push) Failing after 59s
Build and test / check (push) Failing after 1m6s
Build and test / test (push) Failing after 1m15s
Build and test / docs (push) Failing after 50s
commands: deduplicate logic in macros, add more macros
2025-02-23 19:16:58 +01:00

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)
}
}