Files
empidee/src/commands/connection_settings/protocol_enable.rs
T
oysteikt 61e077e6e5
Build and test / check (push) Successful in 1m3s
Build and test / docs (push) Successful in 1m29s
Build and test / test (push) Successful in 1m49s
Build and test / build (push) Successful in 1m58s
commands: remove Command for bi-directional assoc types
Also add a `serialize` stub for responses
2026-07-24 16:32:34 +09:00

55 lines
1.5 KiB
Rust

use crate::{
commands::{CommandRequest, RequestParserError, empty_command_response},
request_tokenizer::RequestTokenizer,
types::Feature,
};
pub struct ProtocolEnableRequest(Vec<Feature>);
impl ProtocolEnableRequest {
pub fn new(features: Vec<Feature>) -> Self {
ProtocolEnableRequest(features)
}
}
impl CommandRequest for ProtocolEnableRequest {
type Response = ProtocolEnableResponse;
const COMMAND: &'static str = "protocol enable";
const MIN_ARGS: u32 = 1;
const MAX_ARGS: Option<u32> = None;
fn serialize(&self) -> String {
let features = self
.0
.iter()
.map(|f| f.to_string())
.collect::<Vec<String>>()
.join(" ");
format!("{} {}", Self::COMMAND, features)
}
fn parse(parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
let mut parts = parts.peekable();
if parts.peek().is_none() {
return Err(Self::missing_arguments_error(0));
}
let features = parts
.enumerate()
.map(|(i, f)| {
f.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: i.try_into().unwrap_or(u32::MAX),
expected_type: "Feature",
raw_input: f.to_owned(),
})
})
.collect::<Result<Vec<Feature>, RequestParserError>>()?;
Ok(ProtocolEnableRequest(features))
}
}
empty_command_response!(ProtocolEnable);