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 alli <= MAX_INDEX, g <= MAX_GENERATION
,MAX_INDEX
must be less than or equal toIndex::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
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.
const MAX_GENERATION: u32
const MAX_GENERATION: u32
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 toMAX_INDEX
,generation
is less than or equal toMAX_GENERATION
,generation
is odd.
Violating these requirements may cause undefined behavior.