1use core::cmp::Ordering;
2
3#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, new)]
5pub struct DeviceId {
6 pub type_id: u16,
8 pub index_id: u32,
10}
11
12pub trait Device: Default + Clone + core::fmt::Debug + Send + Sync {
14 fn from_id(device_id: DeviceId) -> Self;
16 fn to_id(&self) -> DeviceId;
18 fn device_count(type_id: u16) -> usize;
20 fn device_count_total() -> usize {
22 Self::device_count(0)
23 }
24}
25
26impl core::fmt::Display for DeviceId {
27 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
28 f.write_fmt(format_args!("{self:?}"))
29 }
30}
31
32impl Ord for DeviceId {
33 fn cmp(&self, other: &Self) -> Ordering {
34 match self.type_id.cmp(&other.type_id) {
35 Ordering::Equal => self.index_id.cmp(&other.index_id),
36 other => other,
37 }
38 }
39}
40
41impl PartialOrd for DeviceId {
42 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
43 Some(self.cmp(other))
44 }
45}