fn new(uevent: &ffi::OsStr) -> Option<Self> {
        let mut bus_type: Option<BusType> = None;
        let mut vendor_id: Option<u16> = None;
        let mut product_id: Option<u16> = None;
        let mut product_name: Option<String> = None;
        let mut serial_number: Option<String> = None;
        for line in uevent.to_str().unwrap().split("\n") {
            let parts: Vec<&str> = line.split('=').collect();
            if parts.len() != 2 {
                continue;
            }
            match parts[0] {
                "HID_ID" => {
                    let numbers: Vec<u32> = parts[1].split(':').map(|x| u32::from_str_radix(x, 16).unwrap()).collect();
                    if numbers.len() != 3 {
                        continue;
                    }
                    bus_type = BusType::from_u32(numbers[0]);
                    vendor_id = Some(numbers[1] as u16);
                    product_id = Some(numbers[2] as u16);
                },
                "HID_NAME" => {
                    product_name = Some(parts[1].to_owned());
                },
                "HID_UNIQ" => {
                    serial_number = Some(parts[1].to_owned());
                }
                _ => continue,
            }
        }
        match (bus_type, vendor_id, product_id, product_name, serial_number) {
            (Some(b), Some(vid), Some(pid), Some(pn), Some(sn)) => Some(UEventInfo {
                bus_type: b,
                vendor_id: vid,
                product_id: pid,
                product_name: pn,
                serial_number: sn,
            }),
            _ => None
        }
    }
/// Parses a uevent string into a UEventInfo struct
///
/// This returns None if any field is not found
Parses a uevent string into a UEventInfo struct
This returns None if any field is not found
Parses a uevent string into a UEventInfo struct This returns None if any field is not found
fn new(uevent: &ffi::OsStr) -> Option<Self> {
        let mut bus_type: Option<BusType> = None;
        let mut vendor_id: Option<u16> = None;
        let mut product_id: Option<u16> = None;
        let mut product_name: Option<String> = None;
        let mut serial_number: Option<String> = None;
        for line in uevent.to_str().unwrap().split("\n") {
            let parts: Vec<&str> = line.split('=').collect();
            if parts.len() != 2 {
                continue;
            }
            match parts[0] {
                "HID_ID" => {
                    let numbers: Vec<u32> = parts[1].split(':').map(|x| u32::from_str_radix(x, 16).unwrap()).collect();
                    if numbers.len() != 3 {
                        continue;
                    }
                    bus_type = BusType::from_u32(numbers[0]);
                    vendor_id = Some(numbers[1] as u16);
                    product_id = Some(numbers[2] as u16);
                },
                "HID_NAME" => {
                    product_name = Some(parts[1].to_owned());
                },
                "HID_UNIQ" => {
                    serial_number = Some(parts[1].to_owned());
                }
                _ => continue,
            }
        }
        match (bus_type, vendor_id, product_id, product_name, serial_number) {
            (Some(b), Some(vid), Some(pid), Some(pn), Some(sn)) => Some(UEventInfo {
                bus_type: b,
                vendor_id: vid,
                product_id: pid,
                product_name: pn,
                serial_number: sn,
            }),
            _ => None
        }
    }
fn new ( uevent : & ffi :: OsStr ) -> Option < Self > { let mut bus_type : Option < BusType > = None ; let mut vendor_id : Option < u16 > = None ; let mut product_id : Option < u16 > = None ; let mut product_name : Option < String > = None ; let mut serial_number : Option < String > = None ; for line in uevent . to_str ( ) . unwrap ( ) . split ( " \n " ) { let parts : Vec < & str > = line . split ( '=' ) . collect ( ) ; if parts . len ( ) != 2 { continue ; } match parts [ 0 ] { " " => { let numbers : Vec < u32 > = parts [ 1 ] . split ( ':' ) . map ( | x | u32 :: from_str_radix ( x , 16 ) . unwrap ( ) ) . collect ( ) ; if numbers . len ( ) != 3 { continue ; } bus_type = BusType :: from_u32 ( numbers [ 0 ] ) ; vendor_id = Some ( numbers [ 1 ] as u16 ) ; product_id = Some ( numbers [ 2 ] as u16 ) ; } , " " => { product_name = Some ( parts [ 1 ] . to_owned ( ) ) ; } , " " => { serial_number = Some ( parts [ 1 ] . to_owned ( ) ) ; } _ => continue , } } match ( bus_type , vendor_id , product_id , product_name , serial_number ) { ( Some ( b ) , Some ( vid ) , Some ( pid ) , Some ( pn ) , Some ( sn ) ) => Some ( UEventInfo { bus_type : b , vendor_id : vid , product_id : pid , product_name : pn , serial_number : sn , } ) , _ => None } }
Parses a uevent string into a UEventInfo struct
This returns None if any field is not found
Parses a uevent string into a UEventInfo struct This returns None if any field is not found
uevent
&ffi::OsStr