[][src]Struct handy::HandleAlloc

pub struct HandleAlloc { /* fields omitted */ }

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 you'd like to use with them.

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.