Skip to main content

KeyLayout

Trait KeyLayout 

Source
pub unsafe trait KeyLayout<Idx: KeyPiece, Gen: KeyPiece> {
    type Repr: Copy + Eq + Hash + Send + Sync + 'static;

    // Required methods
    fn max_idx() -> Idx;
    fn max_generation() -> Gen;
    unsafe fn pack_unchecked(idx: Idx, generation: Gen) -> Self::Repr;
    fn idx(repr: Self::Repr) -> Idx;
    fn generation(repr: Self::Repr) -> Gen::NonZero;
}
Expand description

How a Key stores its index and generation. A Config picks one through its Layout type.

§Safety

The map trusts what a layout hands back. idx and generation must return exactly what pack_unchecked was given, two Repr values must be equal only if they were packed from the same parts, and max_generation must be odd.

generation is safe to call and returns a NonZero, so safe code must not be able to make a Repr that pack_unchecked did not return. A Repr whose fields are private, like SplitRepr and PackedRepr, meets this rule, because only pack_unchecked can make one.

Required Associated Types§

Source

type Repr: Copy + Eq + Hash + Send + Sync + 'static

The type a key stores its index and generation in.

Required Methods§

Source

fn max_idx() -> Idx

The largest index a key can hold.

Source

fn max_generation() -> Gen

The largest generation a key can hold. It is odd.

Source

unsafe fn pack_unchecked(idx: Idx, generation: Gen) -> Self::Repr

Packs an index and a generation.

§Safety

idx must be at most max_idx, and generation must be odd and at most max_generation.

Source

fn idx(repr: Self::Repr) -> Idx

The index that was packed.

Source

fn generation(repr: Self::Repr) -> Gen::NonZero

The generation that was packed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Idx: KeyPiece, Gen: KeyPiece, R: KeyPiece, const GEN_BITS: u32> KeyLayout<Idx, Gen> for Packed<R, GEN_BITS>

Source§

impl<Idx: KeyPiece, Gen: KeyPiece> KeyLayout<Idx, Gen> for Split

Source§

type Repr = SplitRepr<Idx, Gen>