pub fn parse(&mut self, cmd_param: &str) -> Result<()> {
        if cmd_param.starts_with(',') || cmd_param.ends_with(',') {
            return Err(ErrorKind::InvalidParam(cmd_param.to_string(), self.name.clone()).into());
        }
        let param_items = cmd_param.split(',').collect::<Vec<&str>>();
        for (i, param_item) in param_items.iter().enumerate() {
            if param_item.starts_with('=') || param_item.ends_with('=') {
                return Err(
                    ErrorKind::InvalidParam(param_item.to_string(), self.name.clone()).into(),
                );
            }
            let param = param_item.splitn(2, '=').collect::<Vec<&str>>();
            let (param_key, param_value) = match param.len() {
                1 => {
                    if i == 0 {
                        ("", param[0])
                    } else {
                        (param[0], "")
                    }
                }
                2 => (param[0], param[1]),
                _ => {
                    return Err(
                        ErrorKind::InvalidParam(param_item.to_string(), self.name.clone()).into(),
                    );
                }
            };

            if self.params.contains_key(param_key) {
                let field_value = self.params.get_mut(param_key).unwrap();
                if field_value.is_none() {
                    *field_value = Some(String::from(param_value));
                } else {
                    return Err(
                        ErrorKind::FieldRepeat(self.name.clone(), param_key.to_string()).into(),
                    );
                }
            } else {
                return Err(
                    ErrorKind::InvalidParam(param[0].to_string(), self.name.clone()).into(),
                );
            }
        }

        Ok(())
    }
/// Parse cmdline parameters string into `params`.
///
/// # Arguments
///
/// * `cmd_param`: The whole cmdline parameter string.
Parse cmdline parameters string into `params`.
Parse cmdline parameters string into ` params ` .
pub fn parse(&mut self, cmd_param: &str) -> Result<()> {
        if cmd_param.starts_with(',') || cmd_param.ends_with(',') {
            return Err(ErrorKind::InvalidParam(cmd_param.to_string(), self.name.clone()).into());
        }
        let param_items = cmd_param.split(',').collect::<Vec<&str>>();
        for (i, param_item) in param_items.iter().enumerate() {
            if param_item.starts_with('=') || param_item.ends_with('=') {
                return Err(
                    ErrorKind::InvalidParam(param_item.to_string(), self.name.clone()).into(),
                );
            }
            let param = param_item.splitn(2, '=').collect::<Vec<&str>>();
            let (param_key, param_value) = match param.len() {
                1 => {
                    if i == 0 {
                        ("", param[0])
                    } else {
                        (param[0], "")
                    }
                }
                2 => (param[0], param[1]),
                _ => {
                    return Err(
                        ErrorKind::InvalidParam(param_item.to_string(), self.name.clone()).into(),
                    );
                }
            };
            if self.params.contains_key(param_key) {
                let field_value = self.params.get_mut(param_key).unwrap();
                if field_value.is_none() {
                    *field_value = Some(String::from(param_value));
                } else {
                    return Err(
                        ErrorKind::FieldRepeat(self.name.clone(), param_key.to_string()).into(),
                    );
                }
            } else {
                return Err(
                    ErrorKind::InvalidParam(param[0].to_string(), self.name.clone()).into(),
                );
            }
        }
        Ok(())
    }
pub fn parse ( & mut self , cmd_param : & str ) -> Result < ( ) > { if cmd_param . starts_with ( ',' ) || cmd_param . ends_with ( ',' ) { return Err ( ErrorKind :: InvalidParam ( cmd_param . to_string ( ) , self . name . clone ( ) ) . into ( ) ) ; } let param_items = cmd_param . split ( ',' ) . collect :: < Vec < & str > > ( ) ; for ( i , param_item ) in param_items . iter ( ) . enumerate ( ) { if param_item . starts_with ( '=' ) || param_item . ends_with ( '=' ) { return Err ( ErrorKind :: InvalidParam ( param_item . to_string ( ) , self . name . clone ( ) ) . into ( ) , ) ; } let param = param_item . splitn ( 2 , '=' ) . collect :: < Vec < & str > > ( ) ; let ( param_key , param_value ) = match param . len ( ) { 1 => { if i == 0 { ( " " , param [ 0 ] ) } else { ( param [ 0 ] , " " ) } } 2 => ( param [ 0 ] , param [ 1 ] ) , _ => { return Err ( ErrorKind :: InvalidParam ( param_item . to_string ( ) , self . name . clone ( ) ) . into ( ) , ) ; } } ; if self . params . contains_key ( param_key ) { let field_value = self . params . get_mut ( param_key ) . unwrap ( ) ; if field_value . is_none ( ) { * field_value = Some ( String :: from ( param_value ) ) ; } else { return Err ( ErrorKind :: FieldRepeat ( self . name . clone ( ) , param_key . to_string ( ) ) . into ( ) , ) ; } } else { return Err ( ErrorKind :: InvalidParam ( param [ 0 ] . to_string ( ) , self . name . clone ( ) ) . into ( ) , ) ; } } Ok ( ( ) ) }
Parse cmdline parameters string into `params`.
Parse cmdline parameters string into ` params ` .
&mut self
cmd_param
&str
&mut self
cmd_param
&str