pub fn shrink_custom_checked<Coor, Key>(
x: Key,
siz_rat: NonZeroUsize,
) -> Option<Coor>Expand description
Fallibly “shrinks” a given number, only keeping a certain amount of its bits.
The 0th bit is always kept, and so is every siz_ratth bit thereafter. All
other bits are lost. Alternatively, if the provided Key type is too small
to fit siz_rat Coor numbers inside it, a None is returned .
This function is usable when the size ratio is computed at run-time, but bear in mind that it might run much more slowly than its compile-time counterparts.
This function sanitises its input, so the bits that are thrown away do not need to be cleared by the user.
§Examples
assert_eq!(shrink_custom_checked::<u16, u32>(0xFFFF_FFFF, nz(2)), Some(0xFFFF));
assert_eq!(shrink_custom_checked::<u16, u32>(0x185185, nz(3)), None);