On 8/25/25 5:17 AM, Alexandre Courbot wrote: >> + /// Convert a raw 24-bit class code value to a `Class`. >> + impl From<u32> for Class { >> + fn from(value: u32) -> Self { >> + match value { >> + $(x if x == Self::$variant.0 => Self::$variant,)+ >> + _ => Self::UNKNOWN, >> + } >> + } > > Should we normalize `value` to 24 bits (i.e. call `to_24bit_class`) > before doing the match? The constants we compare against are all > normalized, but if we pass a 16-bit class to this method the result will > be `UNKNOWN`, unless I missed something. > > Being able to store a class as either a 16-bit or 24-bit representation > in the same type also opens the door to bugs, which we can avoid if we > always normalize to 24-bit and make the class/subclass representation > accessible through a convenience method only. It's constrained by the PCI ID patterns, and should only be used in order to get values from the C bindings, actually. > >> + } >> + }; >> +} >> + >> +/// Once constructed, a `Class` contains a valid PCI Class code. >> +impl Class { >> + /// Create a new Class from a raw 24-bit class code. >> + pub fn new(class_code: u32) -> Self { >> + Self::from(class_code) >> + } > > Do we need a `new` method when the `From` implementation does exactly > the same thing and has the same signature? > Looks like I'll remove the From, and only provide new, based on the other thread. thanks, -- John Hubbard