Function morton_encoding::shrink_custom[][src]

pub fn shrink_custom<Coor, Key, const N: usize>(x: Key) -> Coor where
    Coor: ToPrimitive + PrimInt,
    Key: ValidKey<Coor>, 

“Shrinks” a given number, only keeping a user-provided amount of its bits.

The 0th bit is always kept, and so is every siz_ratth bit thereafter. All other bits are lost.

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::<u8, u32, 3>(0x145145), 0x55);

Panics

With the advent of min_const_generics in this crate, it was hoped that this function could recognise when a Key value is not large enough for N Coor values, and fail to compile in that case. Sadly, the compiler isn’t quite clever enough for that yet. Thus, we have to make do with run-time panics instead, as seen in the following example:

shrink_custom::<u8, u16, 3>(0x5555u16); // Compiles, but panics.

Therefore, the user is solely responsible for maintaining the invariants needed.