use crate::{ commands::{CommandRequest, RequestParserError, empty_command_response}, request_tokenizer::RequestTokenizer, types::Feature, }; pub struct ProtocolEnableRequest(Vec); impl ProtocolEnableRequest { pub fn new(features: Vec) -> 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 = None; fn serialize(&self) -> String { let features = self .0 .iter() .map(|f| f.to_string()) .collect::>() .join(" "); format!("{} {}", Self::COMMAND, features) } fn parse(parts: RequestTokenizer<'_>) -> Result { 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::, RequestParserError>>()?; Ok(ProtocolEnableRequest(features)) } } empty_command_response!(ProtocolEnable);