pub fn validate(&self) -> CommLibResult<()> {
        match self {
            Update::LED(id, _) => if id > &2 { return Err(InvalidLed(*id)); }
            Update::Text(text) => {
                let mut invalids = vec![];
                if text.chars().count() > 84 {
                    return Err(TooLong);
                }
                for (i, chr) in text.chars().enumerate() {
                    if !chr.is_ascii_graphic() && chr as u8 != 32 {
                        invalids.push(i);
                    }
                }
                if !invalids.is_empty() {
                    return Err(NotAscii(invalids));
                }
            }
        }
        Ok(())
    }
/// Check that values inside the udpate are valid
Check that values inside the udpate are valid
Check that values inside the udpate are valid
pub fn validate(&self) -> CommLibResult<()> {
        match self {
            Update::LED(id, _) => if id > &2 { return Err(InvalidLed(*id)); }
            Update::Text(text) => {
                let mut invalids = vec![];
                if text.chars().count() > 84 {
                    return Err(TooLong);
                }
                for (i, chr) in text.chars().enumerate() {
                    if !chr.is_ascii_graphic() && chr as u8 != 32 {
                        invalids.push(i);
                    }
                }
                if !invalids.is_empty() {
                    return Err(NotAscii(invalids));
                }
            }
        }
        Ok(())
    }
pub fn validate ( & self ) -> CommLibResult < ( ) > { match self { Update :: LED ( id , _ ) => if id > & 2 { return Err ( InvalidLed ( * id ) ) ; } Update :: Text ( text ) => { let mut invalids = vec ! [ ] ; if text . chars ( ) . count ( ) > 84 { return Err ( TooLong ) ; } for ( i , chr ) in text . chars ( ) . enumerate ( ) { if ! chr . is_ascii_graphic ( ) && chr as u8 != 32 { invalids . push ( i ) ; } } if ! invalids . is_empty ( ) { return Err ( NotAscii ( invalids ) ) ; } } } Ok ( ( ) ) }
Check that values inside the udpate are valid
Check that values inside the udpate are valid
&self
&self