pub unsafe trait Indexed: Sized {
unsafe fn get_index(&self) -> usize;
unsafe fn set_index(&mut self, index: usize);
fn chunk_len() -> ChunkLen { ... }
fn null() -> usize { ... }
fn pool(&self) -> &Pool<Self> { ... }
unsafe fn pool_mut(&self) -> &mut Pool<Self> { ... }
fn pool_non_null(&self) -> NonNull<Pool<Self>> { ... }
fn pool_push(&self, value: Self) { ... }
unsafe fn pool_write(&self, index: usize, value: Self) { ... }
fn pool_reserve(&self, additional: usize) { ... }
}
Expand description
Type of elements in the Pool
must implement this trait.
Typically some integer field in the type must devote to storing the index in the pool, and it is not necessarily usize.
For example, an index can be stored in u32 if 4194304K is enough for anybody.
Required Methods
Provided Methods
sourcefn chunk_len() -> ChunkLen
fn chunk_len() -> ChunkLen
Sets the underlying chunk size. The default is 256, and can be overrided by those values defined in ChunkLen
.
sourcefn null() -> usize
fn null() -> usize
Defines which index value is for null. If the underlying storage for index is smaller than usize
’s size, the library user should override this method and pick a smaller value, e.g !0_u32
for index stored in u32
.
Note that it is for convenience only, and the library will not do any index check against null()
.
sourcefn pool_non_null(&self) -> NonNull<Pool<Self>>
fn pool_non_null(&self) -> NonNull<Pool<Self>>
Obtains non null pointer of its pool.
sourceunsafe fn pool_write(&self, index: usize, value: Self)
unsafe fn pool_write(&self, index: usize, value: Self)
Overwrites a new value into its pool at given index without reading or dropping the old value.
sourcefn pool_reserve(&self, additional: usize)
fn pool_reserve(&self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the given Poolchunk_len()
.
After calling reserve, capacity will be greater than or equal to self.pool().new_index() + additional.
Does nothing if capacity is already sufficient.