fn parse_classes(iter: &mut Lines<'a>) -> Result<HashMap<u8, Class<'a>>, Error> {
        let mut map: HashMap<u8, Class<'a>> = HashMap::new();
        let mut cached_subclass: u8 = 0;
        let mut cached_class: Option<&mut Class<'a>> = None;
        for line in iter {
            if line.is_empty() || line.starts_with('#') {
                continue;
            }

            let len = line.len();
            if line.starts_with('C') {
                let class =
                    u8::from_str_radix(&line[2..4], 16).context(format!("'{}'", &line[2..4]))?;
                let name = &line[6..len];
                map.insert(class, Class { name, subclasses: Vec::new() });
                cached_class = map.get_mut(&class);
            } else {
                match PciDb::count_tabs(line) {
                    1 => {
                        cached_subclass = u8::from_str_radix(&line[1..3], 16)
                            .context(format!("'{}'", &line[1..3]))?;
                        let name = &line[5..len];
                        let c = cached_class.unwrap();
                        c.subclasses.push(SubClass {
                            name,
                            subclass: cached_subclass,
                            prog_if: None,
                        });
                        cached_class = Some(c);
                    }
                    2 => {
                        let prog_if = u8::from_str_radix(&line[2..4], 16)
                            .context(format!("'{}'", &line[2..4]))?;
                        let name = &line[6..len];
                        let c = cached_class.unwrap();
                        c.subclasses.push(SubClass {
                            name,
                            subclass: cached_subclass,
                            prog_if: Some(prog_if),
                        });
                        cached_class = Some(c);
                    }

                    _ => return Err(anyhow!("Invalid line in db: \"{}\"", line)),
                }
            }
        }
        Ok(map)
    }
// Parses the class information out of the iterator, parsing is in a similar format
// to the vendor:device information, but simpler.
Parses the class information out of the iterator, parsing is in a similar format
to the vendor:device information, but simpler.
Parses the class information out of the iterator parsing is in a similar format to the vendor : device information but simpler .
fn parse_classes(iter: &mut Lines<'a>) -> Result<HashMap<u8, Class<'a>>, Error> {
        let mut map: HashMap<u8, Class<'a>> = HashMap::new();
        let mut cached_subclass: u8 = 0;
        let mut cached_class: Option<&mut Class<'a>> = None;
        for line in iter {
            if line.is_empty() || line.starts_with('#') {
                continue;
            }
            let len = line.len();
            if line.starts_with('C') {
                let class =
                    u8::from_str_radix(&line[2..4], 16).context(format!("'{}'", &line[2..4]))?;
                let name = &line[6..len];
                map.insert(class, Class { name, subclasses: Vec::new() });
                cached_class = map.get_mut(&class);
            } else {
                match PciDb::count_tabs(line) {
                    1 => {
                        cached_subclass = u8::from_str_radix(&line[1..3], 16)
                            .context(format!("'{}'", &line[1..3]))?;
                        let name = &line[5..len];
                        let c = cached_class.unwrap();
                        c.subclasses.push(SubClass {
                            name,
                            subclass: cached_subclass,
                            prog_if: None,
                        });
                        cached_class = Some(c);
                    }
                    2 => {
                        let prog_if = u8::from_str_radix(&line[2..4], 16)
                            .context(format!("'{}'", &line[2..4]))?;
                        let name = &line[6..len];
                        let c = cached_class.unwrap();
                        c.subclasses.push(SubClass {
                            name,
                            subclass: cached_subclass,
                            prog_if: Some(prog_if),
                        });
                        cached_class = Some(c);
                    }
                    _ => return Err(anyhow!("Invalid line in db: \"{}\"", line)),
                }
            }
        }
        Ok(map)
    }
fn parse_classes ( iter : & mut Lines < ' a > ) -> Result < HashMap < u8 , Class < ' a > > , Error > { let mut map : HashMap < u8 , Class < ' a > > = HashMap :: new ( ) ; let mut cached_subclass : u8 = 0 ; let mut cached_class : Option < & mut Class < ' a > > = None ; for line in iter { if line . is_empty ( ) || line . starts_with ( '#' ) { continue ; } let len = line . len ( ) ; if line . starts_with ( 'C' ) { let class = u8 :: from_str_radix ( & line [ 2 .. 4 ] , 16 ) . context ( format ! ( " " line [ 2 4 ] ) ) ? ; let name = & line [ 6 .. len ] ; map . insert ( class , Class { name , subclasses : Vec :: new ( ) } ) ; cached_class = map . get_mut ( & class ) ; } else { match PciDb :: count_tabs ( line ) { 1 => { cached_subclass = u8 :: from_str_radix ( & line [ 1 .. 3 ] , 16 ) . context ( format ! ( " " line [ 1 3 ] ) ) ? ; let name = & line [ 5 .. len ] ; let c = cached_class . unwrap ( ) ; c . subclasses . push ( SubClass { name , subclass : cached_subclass , prog_if : None , } ) ; cached_class = Some ( c ) ; } 2 => { let prog_if = u8 :: from_str_radix ( & line [ 2 .. 4 ] , 16 ) . context ( format ! ( " " line [ 2 4 ] ) ) ? ; let name = & line [ 6 .. len ] ; let c = cached_class . unwrap ( ) ; c . subclasses . push ( SubClass { name , subclass : cached_subclass , prog_if : Some ( prog_if ) , } ) ; cached_class = Some ( c ) ; } _ => return Err ( anyhow ! ( " \" \" " line ) ) , } } } Ok ( map ) }
Parses the class information out of the iterator, parsing is in a similar format
to the vendor:device information, but simpler.
Parses the class information out of the iterator parsing is in a similar format to the vendor : device information but simpler .
iter
&mut Lines<'a>
iter
&mut Lines<'a>