34 lines
1003 B
Rust
34 lines
1003 B
Rust
use crate::{
|
|
commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request
|
|
};
|
|
|
|
pub struct Protocol;
|
|
|
|
pub type ProtocolResponse = Vec<String>;
|
|
|
|
impl Command for Protocol {
|
|
type Response = ProtocolResponse;
|
|
const COMMAND: &'static str = "protocol";
|
|
|
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
|
debug_assert!(parts.next().is_none());
|
|
Ok((Request::Protocol, ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError<'_>> {
|
|
for (k, _) in parts.0.iter().filter(|(k, _)| *k != "feature") {
|
|
return Err(ResponseParserError::UnexpectedProperty(k));
|
|
}
|
|
|
|
let list = parts
|
|
.0
|
|
.into_iter()
|
|
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
|
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
|
|
|
Ok(list)
|
|
}
|
|
}
|