use crate::{AsReg, Size};
use alloc::string::String;
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct Fixed<R, const E: u8>(pub R);
impl<R, const E: u8> Fixed<R, E> {
pub fn expected_enc(&self) -> u8 {
E
}
pub fn to_string(&self, size: Option<Size>) -> String
where
R: AsReg,
{
self.0.to_string(size)
}
}
impl<R: AsReg, const E: u8> AsReg for Fixed<R, E> {
fn new(reg: u8) -> Self {
assert!(reg == E);
Self(R::new(reg))
}
fn enc(&self) -> u8 {
assert!(self.0.enc() == E);
self.0.enc()
}
}
impl<R, const E: u8> AsRef<R> for Fixed<R, E> {
fn as_ref(&self) -> &R {
&self.0
}
}
impl<R, const E: u8> From<R> for Fixed<R, E> {
fn from(reg: R) -> Fixed<R, E> {
Fixed(reg)
}
}