bitmaps

Trait Bits

Source
pub trait Bits {
    type Store: BitOps + Default + Copy + PartialEq + Debug;

    const VALUE: usize;

    // Provided methods
    fn corrected_first_false_index(store: &Self::Store) -> Option<usize> { ... }
    fn corrected_last_false_index(store: &Self::Store) -> Option<usize> { ... }
    fn corrected_next_false_index(
        store: &Self::Store,
        index: usize,
    ) -> Option<usize> { ... }
}
Expand description

A type level number signifying the number of bits in a bitmap.

This trait is implemented for type level numbers from U1 to U1024.

§Examples

assert_eq!(
    std::mem::size_of::<<BitsImpl<10> as Bits>::Store>(),
    std::mem::size_of::<u16>()
);

Required Associated Constants§

Source

const VALUE: usize

The number of bits

Required Associated Types§

Source

type Store: BitOps + Default + Copy + PartialEq + Debug

A primitive integer type suitable for storing this many bits.

Provided Methods§

Source

fn corrected_first_false_index(store: &Self::Store) -> Option<usize>

The underlying data type might have some trailing bits, which would result in an invalid value being returned.

Thankfully, this only happens for ‘false_index’-functions (bits higher than VALUE - 1 cannot be set), and even then only for functions that might seek in that area: that is all forward seeking functions, and the one seeking backwards from the end (last_false_index). prev_false_index is not affected, because the supplied index must be valid, and any index lower than that is also valid.

Source

fn corrected_last_false_index(store: &Self::Store) -> Option<usize>

The underlying data type might have some trailing bits, which would result in an invalid result, so we check against that here.

Source

fn corrected_next_false_index( store: &Self::Store, index: usize, ) -> Option<usize>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§