use core::cmp::Ordering;
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, new)]
pub struct DeviceId {
pub type_id: u16,
pub index_id: u32,
}
pub trait Device: Default + Clone + core::fmt::Debug + Send + Sync {
fn from_id(device_id: DeviceId) -> Self;
fn to_id(&self) -> DeviceId;
fn device_count(type_id: u16) -> usize;
fn device_count_total() -> usize {
Self::device_count(0)
}
}
impl core::fmt::Display for DeviceId {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!("{self:?}"))
}
}
impl Ord for DeviceId {
fn cmp(&self, other: &Self) -> Ordering {
match self.type_id.cmp(&other.type_id) {
Ordering::Equal => self.index_id.cmp(&other.index_id),
other => other,
}
}
}
impl PartialOrd for DeviceId {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}