[][src]Struct managed::SlotMap

pub struct SlotMap<'a, T> { /* fields omitted */ }

Provides a slotmap based on external memory.

A slotmap provides a Vec-like interface where each entry is associated with a stable index-like key. Lookup with the key will detect if an entry has been removed but does not require a lifetime relation. Compared to other slotmap implementations this does not internally allocate any memory on its own but only relies on the Slice arguments in the constructor.

Usage

The important aspect is that the slotmap does not create the storage of its own elements, it merely manages one given to it at construction time.


let mut elements = [0usize; 1024];
let mut slots = [SlotIndex::default(); 1024];

let mut map = SlotMap::new(
    ManagedSlice::Borrowed(&mut elements[..]),
    ManagedSlice::Borrowed(&mut slots[..]));
let index = map.insert(42).unwrap();
assert_eq!(map.get(index).cloned(), Some(42));

Implementations

impl<'_, T> SlotMap<'_, T>[src]

pub fn get(&self, index: Key) -> Option<&T>[src]

Retrieve a value by index.

pub fn get_mut(&mut self, index: Key) -> Option<&mut T>[src]

Retrieve a mutable value by index.

pub fn reserve(&mut self) -> Option<(Key, &mut T)>[src]

Reserve a new entry.

In case of success, the returned key refers to the entry until it is removed. The entry itself is not initialized with any particular value but instead retains the value it had in the backing slice. It is only logically placed into the slot map.

pub fn insert(&mut self, value: T) -> Option<Key>[src]

Try to insert a value into the map.

This will fail if there is not enough space. Sugar wrapper around reserve for inserting values. Note that on success, an old value stored in the backing slice will be overwritten. Use reserve directly if it is vital that no old value is dropped.

pub fn remove(&mut self, index: Key) -> Option<&mut T>[src]

Remove an element.

If successful, return a mutable reference to the removed element so that the caller can swap it with a logically empty value. Returns None if the provided index did not refer to an element that could be freed.

impl<'a, T> SlotMap<'a, T>[src]

pub fn new(elements: Slice<'a, T>, slots: Slice<'a, Slot>) -> Self[src]

Create a slot map.

The capacity is the minimum of the capacity of the element and slot slices.

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for SlotMap<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for SlotMap<'a, T> where
    T: Send

impl<'a, T> Sync for SlotMap<'a, T> where
    T: Sync

impl<'a, T> Unpin for SlotMap<'a, T> where
    T: Unpin

impl<'a, T> !UnwindSafe for SlotMap<'a, T>

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, 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.