mctp_rs/
mctp_message_tag.rs1use bit_register::{NumBytes, TryFromBits, TryIntoBits};
2
3#[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub struct MctpMessageTag(u8);
6
7impl TryFrom<u8> for MctpMessageTag {
8 type Error = &'static str;
9 fn try_from(value: u8) -> Result<Self, Self::Error> {
10 if value > 0b111 {
11 return Err("Invalid message tag");
12 }
13 Ok(Self(value))
14 }
15}
16
17impl NumBytes for MctpMessageTag {
18 const NUM_BYTES: usize = 1;
19}
20
21impl TryFromBits<u32> for MctpMessageTag {
22 fn try_from_bits(bits: u32) -> Result<Self, &'static str> {
23 Self::try_from(bits as u8)
24 }
25}
26
27impl TryIntoBits<u32> for MctpMessageTag {
28 fn try_into_bits(self) -> Result<u32, &'static str> {
29 Ok(self.0 as u32)
30 }
31}