[][src]Struct unicycle::pin_slab::PinSlab

pub struct PinSlab<T> { /* fields omitted */ }

Pre-allocated storage for a uniform data type, with slots of immovable memory regions.

Implementations

impl<T> PinSlab<T>[src]

pub fn new() -> Self[src]

Construct a new, empty PinSlab with the default slot size.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();

assert!(!slab.remove(0));
let index = slab.insert(42);
assert!(slab.remove(index));
assert!(!slab.remove(index));

pub fn len(&self) -> usize[src]

Get the length of the slab.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();
assert_eq!(0, slab.len());
assert_eq!(0, slab.insert(42));
assert_eq!(1, slab.len());

pub fn is_empty(&self) -> bool[src]

Test if the pin slab is empty.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();
assert!(slab.is_empty());
assert_eq!(0, slab.insert(42));
assert!(!slab.is_empty());

pub fn insert(&mut self, val: T) -> usize[src]

Insert a value into the pin slab.

pub fn get_pin_mut(&mut self, key: usize) -> Option<Pin<&mut T>>[src]

Access the given key as a pinned mutable value.

pub fn get(&mut self, key: usize) -> Option<&T>[src]

Get a reference to the value at the given slot.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();
let key = slab.insert(42);
assert_eq!(Some(&42), slab.get(key));

pub fn get_mut(&mut self, key: usize) -> Option<&mut T> where
    T: Unpin
[src]

Get a mutable reference to the value at the given slot.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();
let key = slab.insert(42);
*slab.get_mut(key).unwrap() = 43;
assert_eq!(Some(&43), slab.get(key));

pub fn remove(&mut self, key: usize) -> bool[src]

Remove the key from the slab.

Returns true if the entry was removed, false otherwise. Removing a key which does not exist has no effect, and false will be returned.

We need to take care that we don't move it, hence we only perform operations over pointers below.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();

assert!(!slab.remove(0));
let index = slab.insert(42);
assert!(slab.remove(index));
assert!(!slab.remove(index));

pub fn clear(&mut self)[src]

Clear all available data in the PinSlot.

Examples

use unicycle::pin_slab::PinSlab;

let mut slab = PinSlab::new();
assert_eq!(0, slab.insert(42));
slab.clear();
assert!(slab.get(0).is_none());

Trait Implementations

impl<T: Clone> Clone for PinSlab<T>[src]

impl<T> Default for PinSlab<T>[src]

impl<T> Drop for PinSlab<T>[src]

impl<T> Send for PinSlab<T>[src]

impl<T> Sync for PinSlab<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for PinSlab<T> where
    T: RefUnwindSafe

impl<T> Unpin for PinSlab<T>

impl<T> UnwindSafe for PinSlab<T> where
    T: RefUnwindSafe

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.