#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u32)]
pub enum VirtioDeviceType {
Net = 1,
Block = 2,
Console = 3,
Rng = 4,
Balloon = 5,
Vsock = 19,
Pmem = 27,
Mem = 24,
BootTimer = 0xFFFF_FF00,
}
impl VirtioDeviceType {
#[must_use]
pub const fn const_id(self) -> u32 {
self as u32
}
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::Net => "net",
Self::Block => "block",
Self::Console => "console",
Self::Rng => "rng",
Self::Balloon => "balloon",
Self::Vsock => "vsock",
Self::Pmem => "pmem",
Self::Mem => "mem",
Self::BootTimer => "boot-timer",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_use_canonical_virtio_ids_for_standard_devices() {
assert_eq!(VirtioDeviceType::Net.const_id(), 1);
assert_eq!(VirtioDeviceType::Block.const_id(), 2);
assert_eq!(VirtioDeviceType::Console.const_id(), 3);
assert_eq!(VirtioDeviceType::Rng.const_id(), 4);
assert_eq!(VirtioDeviceType::Balloon.const_id(), 5);
assert_eq!(VirtioDeviceType::Vsock.const_id(), 19);
assert_eq!(VirtioDeviceType::Pmem.const_id(), 27);
assert_eq!(VirtioDeviceType::Mem.const_id(), 24);
}
#[test]
fn test_should_use_squib_extension_id_outside_assigned_range_for_boot_timer() {
assert!(VirtioDeviceType::BootTimer.const_id() > 1024);
}
}