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§
Required Methods§
Sourcefn max_generation() -> Gen
fn max_generation() -> Gen
The largest generation a key can hold. It is odd.
Sourceunsafe fn pack_unchecked(idx: Idx, generation: Gen) -> Self::Repr
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.
Sourcefn generation(repr: Self::Repr) -> Gen::NonZero
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".