1use core::str::FromStr;
9
10use crate::error::TwineCodecError;
11
12pub struct Rloc16(u16);
13
14impl From<Rloc16> for u16 {
15 fn from(value: Rloc16) -> Self {
16 value.0
17 }
18}
19
20impl From<u16> for Rloc16 {
21 fn from(rloc16: u16) -> Self {
22 Self(rloc16)
23 }
24}
25
26impl FromStr for Rloc16 {
27 type Err = TwineCodecError;
28
29 fn from_str(s: &str) -> Result<Self, Self::Err> {
30 let value = u16::from_str_radix(s, 16).map_err(|_| TwineCodecError::StringParseError)?;
31 Ok(Self(value))
32 }
33}
34
35impl core::fmt::Display for Rloc16 {
36 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37 write!(f, "0x{:04x}", self.0)
38 }
39}