use crate::{Error, Head};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Type {
Hardware,
Acpi,
Messaging,
Media,
Bios,
}
impl Type {
pub(crate) const fn decode(value: u8) -> Result<Self, u8> {
match value {
0x01 => Ok(Self::Hardware),
0x02 => Ok(Self::Acpi),
0x03 => Ok(Self::Messaging),
0x04 => Ok(Self::Media),
0x05 => Ok(Self::Bios),
n => Err(n),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Node {
Hardware(crate::hw::Hardware),
Acpi(crate::acpi::Acpi),
Messaging(crate::msg::Messaging),
Media(crate::media::Media),
Bios(crate::bios::Bios),
}
impl TryFrom<Head<'_>> for Node {
type Error = Error;
fn try_from(head: Head<'_>) -> Result<Self, Self::Error> {
match Type::decode(head.kind) {
Ok(Type::Hardware) => TryFrom::try_from(head).map(Node::Hardware),
Ok(Type::Acpi) => TryFrom::try_from(head).map(Node::Acpi),
Ok(Type::Messaging) => TryFrom::try_from(head).map(Node::Messaging),
Ok(Type::Media) => TryFrom::try_from(head).map(Node::Media),
Ok(Type::Bios) => TryFrom::try_from(head).map(Node::Bios),
Err(n) => Err(Error::UnknownType(n)),
}
}
}