async_backplane/
device_id.rs

1use core::fmt;
2pub use core::convert::From;
3
4/// A locally unique identifier for a Device.
5#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)]
6pub struct DeviceID {
7    pub(crate) inner: usize,
8}
9
10impl DeviceID {
11    pub(crate) fn new(inner: usize) -> DeviceID {
12        DeviceID { inner }
13    }
14}
15
16impl From<DeviceID> for usize {
17    fn from(did: DeviceID) -> usize { did.inner }
18}
19
20impl fmt::Debug for DeviceID {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.write_fmt(format_args!("DeviceID<{:x}>", self.inner))
23    }
24}
25
26impl fmt::Display for DeviceID {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        f.write_fmt(format_args!("DeviceID<{:x}>", self.inner))
29    }
30}