[−][src]Struct sharded_slab::Slab
A sharded slab.
See the crate-level documentation for details on using this type.
Methods
impl<T> Slab<T>
[src]
pub fn new() -> Self
[src]
Returns a new slab with the default configuration parameters.
pub fn new_with_config<C: Config>() -> Slab<T, C>
[src]
Returns a new slab with the provided configuration parameters.
impl<T, C: Config> Slab<T, C>
[src]
pub const USED_BITS: usize
[src]
The number of bits in each index which are used by the slab.
If other data is packed into the usize
indices returned by
Slab::insert
, user code is free to use any bits higher than the
USED_BITS
-th bit freely.
This is determined by the Config
type that configures the slab's
parameters. By default, all bits are used; this can be changed by
overriding the Config::RESERVED_BITS
constant.
pub fn insert(&self, value: T) -> Option<usize>
[src]
Inserts a value into the slab, returning a key that can be used to access it.
If this function returns None
, then the shard for the current thread
is full and no items can be added until some are removed, or the maximum
number of shards has been reached.
Examples
let slab = Slab::new(); let key = slab.insert("hello world").unwrap(); assert_eq!(slab.get(key), Some(&"hello world"));
pub fn remove(&self, idx: usize) -> Option<T>
[src]
Removes the value associated with the given key from the slab, returning it.
If the slab does not contain a value for that key, None
is returned
instead.
pub fn get(&self, key: usize) -> Option<&T>
[src]
Return a reference to the value associated with the given key.
If the slab does not contain a value for the given key, None
is
returned instead.
Examples
let slab = sharded_slab::Slab::new(); let key = slab.insert("hello world").unwrap(); assert_eq!(slab.get(key), Some(&"hello world")); assert_eq!(slab.get(12345), None);
pub fn contains(&self, key: usize) -> bool
[src]
Returns true
if the slab contains a value for the given key.
Examples
let slab = sharded_slab::Slab::new(); let key = slab.insert("hello world").unwrap(); assert!(slab.contains(key)); slab.remove(key).unwrap(); assert!(!slab.contains(key));
pub fn unique_iter<'a>(&'a mut self) -> UniqueIter<'a, T, C>
[src]
Returns an iterator over all the items in the slab.
Trait Implementations
impl<T: Send, C: Config> Send for Slab<T, C>
[src]
impl<T: Sync, C: Config> Sync for Slab<T, C>
[src]
impl<T: Debug, C: Config> Debug for Slab<T, C>
[src]
Auto Trait Implementations
impl<T, C> Unpin for Slab<T, C> where
C: Unpin,
C: Unpin,
impl<T, C> UnwindSafe for Slab<T, C> where
C: UnwindSafe,
T: UnwindSafe,
C: UnwindSafe,
T: UnwindSafe,
impl<T, C = DefaultConfig> !RefUnwindSafe for Slab<T, C>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,