pub trait Narrow{ type Output; fn narrow(self)->Self::Output; } #[derive(Debug)] pub enum NarrowError{ Overflow, Underflow, } pub trait TryNarrow{ type Output; fn try_narrow(self)->Result; } #[cfg(test)] mod tests { use super::*; impl TryNarrow for i16{ type Output=i8; fn try_narrow(self)->Result{ if self{ type Output=i8; fn narrow(self)->Self::Output{ (self.to_bits()>>8) as i8 } } #[test] fn test_fixed_i16_i8(){ let a=fixed::FixedI16::::from(5)/2; assert_eq!(a.narrow(),2); } }