use crate::types::{DeviceId, SubvendorId, SubdeviceId};
#[derive(Debug, Clone)]
pub struct Subsystem {
pub subvendor_id: SubvendorId,
pub subdevice_id: SubdeviceId,
pub name: &'static str,
}
impl Subsystem {
#[inline]
pub const fn new(subvendor_id: SubvendorId, subdevice_id: SubdeviceId, name: &'static str) -> Self {
Self {
subvendor_id,
subdevice_id,
name,
}
}
#[inline]
pub const fn subvendor_id(&self) -> SubvendorId {
self.subvendor_id
}
#[inline]
pub const fn subdevice_id(&self) -> SubdeviceId {
self.subdevice_id
}
#[inline]
pub const fn name(&self) -> &'static str {
self.name
}
}
impl PartialEq for Subsystem {
fn eq(&self, other: &Self) -> bool {
self.subvendor_id == other.subvendor_id && self.subdevice_id == other.subdevice_id
}
}
impl Eq for Subsystem {}
#[derive(Debug, Clone)]
pub struct Device {
pub id: DeviceId,
pub name: &'static str,
pub subsystems: &'static [Subsystem],
}
impl Device {
#[inline]
pub const fn new(id: DeviceId, name: &'static str, subsystems: &'static [Subsystem]) -> Self {
Self { id, name, subsystems }
}
#[inline]
pub const fn id(&self) -> DeviceId {
self.id
}
#[inline]
pub const fn name(&self) -> &'static str {
self.name
}
#[inline]
pub const fn subsystems(&self) -> &'static [Subsystem] {
self.subsystems
}
pub fn find_subsystem(&self, subvendor_id: SubvendorId, subdevice_id: SubdeviceId) -> Option<&Subsystem> {
self.subsystems.iter().find(|subsystem| {
subsystem.subvendor_id == subvendor_id && subsystem.subdevice_id == subdevice_id
})
}
#[inline]
pub const fn subsystem_count(&self) -> usize {
self.subsystems.len()
}
pub fn has_subsystem(&self, subvendor_id: SubvendorId, subdevice_id: SubdeviceId) -> bool {
self.find_subsystem(subvendor_id, subdevice_id).is_some()
}
pub fn iter_subsystems(&self) -> core::slice::Iter<'_, Subsystem> {
self.subsystems.iter()
}
}
impl PartialEq for Device {
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
impl Eq for Device {}
impl PartialOrd for Device {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Device {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.id.cmp(&other.id)
}
}