use crate::types::{VendorId, DeviceId};
use crate::devices::Device;
#[derive(Debug, Clone)]
pub struct Vendor {
pub id: VendorId,
pub name: &'static str,
pub devices: &'static [Device],
}
impl Vendor {
#[inline]
pub const fn new(id: VendorId, name: &'static str, devices: &'static [Device]) -> Self {
Self { id, name, devices }
}
#[inline]
pub const fn id(&self) -> VendorId {
self.id
}
#[inline]
pub const fn name(&self) -> &'static str {
self.name
}
#[inline]
pub const fn devices(&self) -> &'static [Device] {
self.devices
}
pub fn find_device(&self, device_id: DeviceId) -> Option<&Device> {
self.devices.iter().find(|device| device.id() == device_id)
}
#[inline]
pub const fn device_count(&self) -> usize {
self.devices.len()
}
pub fn has_device(&self, device_id: DeviceId) -> bool {
self.find_device(device_id).is_some()
}
pub fn iter_devices(&self) -> core::slice::Iter<'_, Device> {
self.devices.iter()
}
}
impl PartialEq for Vendor {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for Vendor {}
impl PartialOrd for Vendor {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Vendor {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.id.cmp(&other.id)
}
}
pub mod well_known {
use super::VendorId;
pub const INTEL: VendorId = VendorId::new(0x8086);
pub const AMD: VendorId = VendorId::new(0x1022);
pub const NVIDIA: VendorId = VendorId::new(0x10de);
pub const BROADCOM: VendorId = VendorId::new(0x14e4);
pub const REALTEK: VendorId = VendorId::new(0x10ec);
pub const QUALCOMM: VendorId = VendorId::new(0x17cb);
pub const MARVELL: VendorId = VendorId::new(0x11ab);
pub const VIA: VendorId = VendorId::new(0x1106);
pub const ATHEROS: VendorId = VendorId::new(0x168c);
pub const THREECOM: VendorId = VendorId::new(0x10b7);
}