pub unsafe trait Handle: Copy + Debug + Eq + Hash + Ord {
    type Index: Capacity;

    const MAX_INDEX: usize;
    const MAX_GENERATION: u32;

    unsafe fn new(index: usize, generation: u32) -> Self;
fn into_raw_parts(self) -> (usize, u32); }
Expand description

Stable references to values stored in a pool.

Safety

Implementors must ensure that the following restrictions are met:

  • Handle::new(i, g).into_raw_parts() == (i, g) for all i <= MAX_INDEX, g <= MAX_GENERATION,
  • MAX_INDEX must be less than or equal to Index::MAX_REPRESENTABLE,
  • MAX_GENERATION must be one less than a power of two.

Using handle_type! should be preferred over implementing this manually.

Associated Types

The type pools should use for indices into their storage space.

Associated Constants

The maximum representable index; the maximum capacity of a pool using this handle type is equal to MAX_INDEX - 1 because the maximum index is reserved as a sentinel value.

The maximum representable generation count.

Required methods

Constructs a new handle from the storage location and generation count.

Safety

Implementors may assume the following preconditions:

  • index is less than or equal to MAX_INDEX,
  • generation is less than or equal to MAX_GENERATION,
  • generation is odd.

Violating these requirements may cause undefined behavior.

Returns the storage location and generation count packed into the handle.

Implementors