Files
empidee/src/commands/reflection/commands.rs
T

33 lines
1011 B
Rust

use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError, expect_property_type,
};
pub struct Commands;
pub type CommandsResponse = Vec<String>;
impl Command for Commands {
type Response = CommandsResponse;
const COMMAND: &'static str = "commands";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
debug_assert!(parts.next().is_none());
Ok((Request::Commands, ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
let parts: Vec<_> = parts.into();
let mut result = Vec::new();
for (key, value) in parts.into_iter() {
if key != "command" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
result.push(expect_property_type!(Some(value), "key", Text).to_string());
}
Ok(result)
}
}