fn parse_devices(iter: &mut Lines<'a>) -> Result<HashMap<u16, Vendor<'a>>, Error> {
        // The flat text DB is represented as a tree, so we can cache vendor
        // and device values to avoid excessive key lookups in the map.
        let mut map: HashMap<u16, Vendor<'a>> = HashMap::new();
        let mut cached_device: u16 = 0;
        let mut cached_vendor: Option<&mut Vendor<'a>> = None;
        for line in iter {
            let trimmed = line.trim();
            let len = trimmed.len();
            // Newlines and comments
            if trimmed.is_empty() || line.starts_with('#') {
                continue;
            }

            // Indent level determines the type of node we are working with.
            match PciDb::count_tabs(line) {
                0 => {
                    // vendor vendor_name
                    // ex: 0014 Loongson Technology LLC
                    let vendor = u16::from_str_radix(&trimmed[0..4], 16)?;
                    let name = &trimmed[6..len];
                    map.insert(vendor, Vendor { name, devices: Vec::new() });
                    if vendor == 0xffff {
                        break;
                    }
                    cached_vendor = map.get_mut(&vendor);
                }
                1 => {
                    // device  device_name
                    // ex: \t0014  Loongson Technology LLC
                    cached_device = u16::from_str_radix(&trimmed[0..4], 16)?;
                    let name = &trimmed[6..len];
                    let v = cached_vendor.unwrap();
                    v.devices.push(Device {
                        name,
                        device: cached_device,
                        subvendor: None,
                        subdevice: None,
                    });
                    cached_vendor = Some(v);
                }
                2 => {
                    // subvendor subdevice  subsystem_name
                    // ex: \t\t001c 0004  2 Channel CAN Bus SJC1000
                    let subvendor = u16::from_str_radix(&trimmed[0..4], 16);
                    let subdevice = u16::from_str_radix(&trimmed[6..10], 16);
                    let name = &trimmed[10..len];

                    let v = cached_vendor.unwrap();
                    v.devices.push(Device {
                        name,
                        device: cached_device,
                        subvendor: subvendor.ok(),
                        subdevice: subdevice.ok(),
                    });
                    cached_vendor = Some(v);
                }
                _ => return Err(anyhow!("Invalid line in db: \"{}\"", line)),
            }
        }

        Ok(map)
    }
// Parses from the input buffer's iterator until the final vendor id is seen.
Parses from the input buffer's iterator until the final vendor id is seen.
Parses from the input buffer ' s iterator until the final vendor id is seen .
fn parse_devices(iter: &mut Lines<'a>) -> Result<HashMap<u16, Vendor<'a>>, Error> {
        // The flat text DB is represented as a tree, so we can cache vendor
        // and device values to avoid excessive key lookups in the map.
        let mut map: HashMap<u16, Vendor<'a>> = HashMap::new();
        let mut cached_device: u16 = 0;
        let mut cached_vendor: Option<&mut Vendor<'a>> = None;
        for line in iter {
            let trimmed = line.trim();
            let len = trimmed.len();
            // Newlines and comments
            if trimmed.is_empty() || line.starts_with('#') {
                continue;
            }
            // Indent level determines the type of node we are working with.
            match PciDb::count_tabs(line) {
                0 => {
                    // vendor vendor_name
                    // ex: 0014 Loongson Technology LLC
                    let vendor = u16::from_str_radix(&trimmed[0..4], 16)?;
                    let name = &trimmed[6..len];
                    map.insert(vendor, Vendor { name, devices: Vec::new() });
                    if vendor == 0xffff {
                        break;
                    }
                    cached_vendor = map.get_mut(&vendor);
                }
                1 => {
                    // device  device_name
                    // ex: \t0014  Loongson Technology LLC
                    cached_device = u16::from_str_radix(&trimmed[0..4], 16)?;
                    let name = &trimmed[6..len];
                    let v = cached_vendor.unwrap();
                    v.devices.push(Device {
                        name,
                        device: cached_device,
                        subvendor: None,
                        subdevice: None,
                    });
                    cached_vendor = Some(v);
                }
                2 => {
                    // subvendor subdevice  subsystem_name
                    // ex: \t\t001c 0004  2 Channel CAN Bus SJC1000
                    let subvendor = u16::from_str_radix(&trimmed[0..4], 16);
                    let subdevice = u16::from_str_radix(&trimmed[6..10], 16);
                    let name = &trimmed[10..len];
                    let v = cached_vendor.unwrap();
                    v.devices.push(Device {
                        name,
                        device: cached_device,
                        subvendor: subvendor.ok(),
                        subdevice: subdevice.ok(),
                    });
                    cached_vendor = Some(v);
                }
                _ => return Err(anyhow!("Invalid line in db: \"{}\"", line)),
            }
        }
        Ok(map)
    }
fn parse_devices ( iter : & mut Lines < ' a > ) -> Result < HashMap < u16 , Vendor < ' a > > , Error > { // The flat text DB is represented as a tree, so we can cache vendor // and device values to avoid excessive key lookups in the map. let mut map : HashMap < u16 , Vendor < ' a > > = HashMap :: new ( ) ; let mut cached_device : u16 = 0 ; let mut cached_vendor : Option < & mut Vendor < ' a > > = None ; for line in iter { let trimmed = line . trim ( ) ; let len = trimmed . len ( ) ; // Newlines and comments if trimmed . is_empty ( ) || line . starts_with ( '#' ) { continue ; } // Indent level determines the type of node we are working with. match PciDb :: count_tabs ( line ) { 0 => { // vendor vendor_name // ex: 0014 Loongson Technology LLC let vendor = u16 :: from_str_radix ( & trimmed [ 0 .. 4 ] , 16 ) ? ; let name = & trimmed [ 6 .. len ] ; map . insert ( vendor , Vendor { name , devices : Vec :: new ( ) } ) ; if vendor == 0xffff { break ; } cached_vendor = map . get_mut ( & vendor ) ; } 1 => { // device  device_name // ex: \t0014  Loongson Technology LLC cached_device = u16 :: from_str_radix ( & trimmed [ 0 .. 4 ] , 16 ) ? ; let name = & trimmed [ 6 .. len ] ; let v = cached_vendor . unwrap ( ) ; v . devices . push ( Device { name , device : cached_device , subvendor : None , subdevice : None , } ) ; cached_vendor = Some ( v ) ; } 2 => { // subvendor subdevice  subsystem_name // ex: \t\t001c 0004  2 Channel CAN Bus SJC1000 let subvendor = u16 :: from_str_radix ( & trimmed [ 0 .. 4 ] , 16 ) ; let subdevice = u16 :: from_str_radix ( & trimmed [ 6 .. 10 ] , 16 ) ; let name = & trimmed [ 10 .. len ] ; let v = cached_vendor . unwrap ( ) ; v . devices . push ( Device { name , device : cached_device , subvendor : subvendor . ok ( ) , subdevice : subdevice . ok ( ) , } ) ; cached_vendor = Some ( v ) ; } _ => return Err ( anyhow ! ( " \" \" " line ) ) , } } Ok ( map ) }
Parses from the input buffer's iterator until the final vendor id is seen.
Parses from the input buffer ' s iterator until the final vendor id is seen .
iter
&mut Lines<'a>
iter
&mut Lines<'a>