#![no_std]
pub trait SafeShl: Sized {
fn safe_shl(self, n: u32) -> Option<Self>;
}
macro_rules! ty {
($ty:ident) => {
impl SafeShl for $ty {
fn safe_shl(self, n: u32) -> Option<$ty> {
if n <= self.leading_zeros() {
self.checked_shl(n)
} else {
None
}
}
}
pub fn $ty(lhs: $ty, rhs: u32) -> Option<$ty> {
lhs.safe_shl(rhs)
}
}
}
ty!(u8);
ty!(u16);
ty!(u32);
ty!(u64);
ty!(i8);
ty!(i16);
ty!(i32);
ty!(i64);