Lines
0 %
Functions
use crate::{
commands::{Command, RequestParserError, ResponseParserError},
request_tokenizer::RequestTokenizer,
response_tokenizer::{ResponseAttributes, expect_property_type},
};
pub struct Commands;
pub type CommandsResponse = Vec<String>;
impl Command for Commands {
type Request = ();
type Response = CommandsResponse;
const COMMAND: &'static str = "commands";
fn serialize_request(&self, _request: Self::Request) -> String {
Self::COMMAND.to_string()
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> Result<Self::Request, RequestParserError> {
debug_assert!(parts.next().is_none());
Ok(())
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
let parts: Vec<_> = parts.into_vec()?;
let mut result = Vec::with_capacity(parts.len());
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)