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::*; //TODO: use num_traits to do a blanket implementation (selfResult{ 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); } }