Lines
0 %
Functions
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
};
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));
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"handler", "Binary",
));
result.push(value.to_string());
Ok(result)