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

33 lines
1.1 KiB
Rust

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