pub struct SharedVec<T, K: Key = DefaultKey> { /* private fields */ }
Expand description
A SharedVec
for storing values of a single type.
Implementations§
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs an empty SharedVec
with a capacity of DEFAULT_CAPACITY
.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs an empty SharedVec
able to store at least capacity values before
needing to allocate.
Sourcepub fn push(&self, value: T) -> (K, &T)
pub fn push(&self, value: T) -> (K, &T)
Pushes a value onto the SharedVec
potentially allocating more memory.
Sourcepub fn push_with<F: FnOnce(K) -> T>(&self, func: F) -> (K, &T)
pub fn push_with<F: FnOnce(K) -> T>(&self, func: F) -> (K, &T)
Pushes a value produced by func onto the SharedVec
potentially allocating
more memory.
This method takes a function which is provided with the key where the value will be stored and produces the value to be stored. It allows storing the key of a value inside the value itself.
§Panics
May panic if the provided function accesses the SharedVec
in any way.
Sourcepub fn try_push_with<F: FnOnce(K) -> T>(&self, func: F) -> Result<(K, &T), F>
pub fn try_push_with<F: FnOnce(K) -> T>(&self, func: F) -> Result<(K, &T), F>
Sourcepub fn get_mut(&mut self, key: K) -> Option<&mut T>
pub fn get_mut(&mut self, key: K) -> Option<&mut T>
Returns an exclusive reference to the value stored for the given key.
For details see get
.
Sourcepub fn key_from_index(&self, index: usize) -> Option<K>
pub fn key_from_index(&self, index: usize) -> Option<K>
Returns a key corresponding to the provided index if a value is stored at the given index.
The complexity is O(log n).