pub const MID_LEN: usize = 1;
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ManufacturerId(u8);
impl ManufacturerId {
pub const fn new() -> Self {
Self(0)
}
pub const fn bits(&self) -> u8 {
self.0
}
pub const fn from_bits(val: u8) -> Self {
Self(val)
}
}
impl Default for ManufacturerId {
fn default() -> Self {
Self::new()
}
}
impl From<u8> for ManufacturerId {
fn from(val: u8) -> Self {
Self::from_bits(val)
}
}
impl From<ManufacturerId> for u8 {
fn from(val: ManufacturerId) -> Self {
val.bits()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_valid() {
assert_eq!(ManufacturerId::new().bits(), 0);
(0..u8::MAX).for_each(|id| {
let exp_mid = ManufacturerId(id);
assert_eq!(ManufacturerId::from_bits(id), exp_mid);
assert_eq!(exp_mid.bits(), id);
});
}
}