[−][src]Struct handy::HandleAlloc
An allocator for handle values. This is useful if you need direct control over handle storage, for example if you want use this library just to provide abstract generational indices which can be used in multiple backing arrays.
Besides the name, the only difference between HandleAlloc
and a
HandleMap<()>
is that HandleAlloc
completely ignores the value in the
meta
field of the handle, which the HandleMap
uses for the map id.
The primary use case for this is if you want to use the handles to index
into separate storage, for example if you have more than one Vec
Implementations
impl HandleAlloc
[src]
pub fn new() -> Self
[src]
Construct a new handle allocator.
pub fn with_capacity(c: usize) -> Self
[src]
Returns a new allocator with the requested capacity.
pub fn capacity(&self) -> usize
[src]
Returns the capacity of this handle allocator, which is equivalent to
the maximum possible index
value a handle may currently have at the
moment.
pub fn len(&self) -> usize
[src]
Returns the number of slots that are currently occupied.
pub fn is_empty(&self) -> bool
[src]
Returns true if there are no currently occupied slots.
pub fn clear(&mut self)
[src]
Deallocate all current slots. Note that this changes all of their generations, and also defragments the free-list so that lower items are once again preferred.
pub fn reserve(&mut self, sz: usize)
[src]
Reserve space for sz
additional handles.
pub fn alloc(&mut self) -> Handle
[src]
Allocate a handle. This is O(1) unless we must reallocate the backing memory.
In general, the algorithm attempts to return handles with lower indices preferentially, but this is not guaranteed. For example, the current implementation of the allocator uses a free list, and dealloc adds items to the front of that list.
pub fn dealloc(&mut self, h: Handle) -> bool
[src]
Deallocate a handle, freeing its index to be returned from a subsequent call to alloc.
pub fn handle_for_index(&self, index: usize) -> Option<Handle>
[src]
If index
refers to an occupied entry, return an index to it.
Otherwise, return None.
pub fn test_handle(&self, h: Handle) -> Option<usize>
[src]
If h
is a valid handle, get it's index value. Otherwise return None.
pub fn contains(&self, h: Handle) -> bool
[src]
Returns true if h
is valid handle that refers to an occupied slot in
this allocator.
Trait Implementations
impl Clone for HandleAlloc
[src]
fn clone(&self) -> HandleAlloc
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for HandleAlloc
[src]
impl Default for HandleAlloc
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,