use core::str::FromStr;
use crate::error::TwineCodecError;
pub struct Rloc16(u16);
impl From<Rloc16> for u16 {
fn from(value: Rloc16) -> Self {
value.0
}
}
impl From<u16> for Rloc16 {
fn from(rloc16: u16) -> Self {
Self(rloc16)
}
}
impl FromStr for Rloc16 {
type Err = TwineCodecError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let value = u16::from_str_radix(s, 16).map_err(|_| TwineCodecError::StringParseError)?;
Ok(Self(value))
}
}
impl core::fmt::Display for Rloc16 {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "0x{:04x}", self.0)
}
}