Trait bitmap::Element [] [src]

pub trait Element: Sized {
    type W: Copy;
    type R: Copy;
    fn width(_: Self::W) -> usize;
    fn from_bits(bits: u64) -> Option<Self::R>;
    fn to_bits(_: Self::R) -> u64;
}

The "element type" of a bitmap

Types implementing this trait can be stored in a bitmap. However, you shouldn't need to implement this trait yourself if you only care about semantics-free bits: use one of the fixed-width types defined here, such as OneBit, TwoBits, etc, or the DynamicWidth type.

However, this can be used to make the Bitmap strongly typed storage for types such as those generated by the bitflags! macro.

Associated Types

Type passed to the width method.

Type decoded from from_bits and thus Bitmap::get.

Required Methods

Return the width of values of this type, in bits.

This method is called somewhat frequently, on almost every access to the Bitmap. However, the value it is passed is only ever specified in one place: Bitmap::from_storage.

This should never return a value greater than 64, and should always return the same value for the same Bitmap.

Decode a value from raw bits.

Encode a value into raw bits.

No bits outside of the least significant Element::width(w) bits should be set.

Implementors