/// Try to interpret a DataElement as a ProfileDesciptor.
/// Returns None if the DataElement is not in the correct format to represent a ProfileDescriptor.
Try to interpret a DataElement as a ProfileDesciptor.
Returns None if the DataElement is not in the correct format to represent a ProfileDescriptor.
Try to interpret a DataElement as a ProfileDesciptor . Returns None if the DataElement is not in the correct format to represent a ProfileDescriptor .
pub fn elem_to_profile_descriptor(elem: &DataElement) -> Option<ProfileDescriptor> {
    if let DataElement::Sequence(seq) = elem {
        if seq.len() != 2 {
            return None;
        }
        if seq[0].is_none() {
            return None;
        }
        let profile_id = match **seq[0].as_ref().expect("not none") {
            DataElement::Uuid(uuid) => {
                let uuid: Uuid = uuid.into();
                match uuid.try_into() {
                    Err(_) => return None,
                    Ok(profile_id) => profile_id,
                }
            }
            _ => return None,
        };
        if seq[1].is_none() {
            return None;
        }
        let [major_version, minor_version] = match **seq[1].as_ref().expect("not none") {
            DataElement::Uint16(val) => val.to_be_bytes(),
            _ => return None,
        };
        return Some(ProfileDescriptor { profile_id, major_version, minor_version });
    }
    None
}
pub fn elem_to_profile_descriptor ( elem : & DataElement ) -> Option < ProfileDescriptor > { if let DataElement :: Sequence ( seq ) = elem { if seq . len ( ) != 2 { return None ; } if seq [ 0 ] . is_none ( ) { return None ; } let profile_id = match * * seq [ 0 ] . as_ref ( ) . expect ( " " ) { DataElement :: Uuid ( uuid ) => { let uuid : Uuid = uuid . into ( ) ; match uuid . try_into ( ) { Err ( _ ) => return None , Ok ( profile_id ) => profile_id , } } _ => return None , } ; if seq [ 1 ] . is_none ( ) { return None ; } let [ major_version , minor_version ] = match * * seq [ 1 ] . as_ref ( ) . expect ( " " ) { DataElement :: Uint16 ( val ) => val . to_be_bytes ( ) , _ => return None , } ; return Some ( ProfileDescriptor { profile_id , major_version , minor_version } ) ; } None }
Try to interpret a DataElement as a ProfileDesciptor.
Try to interpret a DataElement as a ProfileDesciptor .
elem
&DataElement