awdl_frame_parser/common/
awdl_version.rs

1use core::fmt::Display;
2
3use macro_bits::bitfield;
4
5bitfield! {
6    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
7    /// A version in AWDL format.
8    pub struct AWDLVersion: u8 {
9        /// The major version.
10        pub major: u8 => 0xf0,
11
12        /// The minor version.
13        pub minor: u8 => 0x0f
14    }
15}
16impl PartialOrd for AWDLVersion {
17    fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
18        use core::cmp::Ordering::*;
19        let cmp = (self.major.cmp(&other.major), self.minor.cmp(&other.minor));
20        match cmp {
21            (Less, _) | (Equal, Less) => Some(Less),
22            (Equal, Equal) => Some(Equal),
23            _ => Some(Greater),
24        }
25    }
26}
27impl Display for AWDLVersion {
28    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
29        f.write_fmt(format_args!("{}.{}", self.major, self.minor))
30    }
31}