Struct SharedVec

Source
pub struct SharedVec<T, K: Key = DefaultKey> { /* private fields */ }
Expand description

A SharedVec for storing values of a single type.

Implementations§

Source§

impl<T, K: Key> SharedVec<T, K>

Source

pub fn new() -> Self

Constructs an empty SharedVec with a capacity of DEFAULT_CAPACITY.

Source

pub fn with_capacity(capacity: usize) -> Self

Constructs an empty SharedVec able to store at least capacity values before needing to allocate.

Source

pub fn push(&self, value: T) -> (K, &T)

Pushes a value onto the SharedVec potentially allocating more memory.

Source

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.

Source

pub fn try_push(&self, value: T) -> Result<(K, &T), T>

Tries to push a value onto the SharedVec without allocating more memory.

§Errors

Fails in case no space is available in the SharedVec.

Source

pub fn try_push_with<F: FnOnce(K) -> T>(&self, func: F) -> Result<(K, &T), F>

Same as push_with but without allocating more memory.

See push_with and try_push.

Source

pub fn len(&self) -> usize

The number of values stored in the SharedVec.

Source

pub fn is_empty(&self) -> bool

Checks whether the SharedVec is empty.

Source

pub fn get(&self, key: K) -> Option<&T>

Returns a shared reference to the value stored for the given key.

The complexity is O(1) if the key has been returned by this SharedVec. It is O(log n) if the key cannot be found or it has been serialized and deserialized without also serializing and deserializing the SharedVec.

Source

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.

Source

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

Source

pub fn into_vec(self) -> Vec<T>

Turns the SharedVec into a Vec.

The index of Key can be used as an index into the returned Vec.

Source

pub fn iter(&self) -> Iter<'_, T, K>

Returns an Iterator over the stored key-value pairs.

Trait Implementations§

Source§

impl<T: Clone, K: Clone + Key> Clone for SharedVec<T, K>

Source§

fn clone(&self) -> SharedVec<T, K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, K: Debug + Key> Debug for SharedVec<T, K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, K: Key> Default for SharedVec<T, K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, K: Key> From<SharedVec<T, K>> for Vec<T>

Source§

fn from(sharedvec: SharedVec<T, K>) -> Self

Converts to this type from the input type.
Source§

impl<T, K: Key> From<Vec<T>> for SharedVec<T, K>

Source§

fn from(chunk: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, K: Key> FromIterator<T> for SharedVec<T, K>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, K: Key> Index<K> for SharedVec<T, K>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: K) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, K: Key> IndexMut<K> for SharedVec<T, K>

Source§

fn index_mut(&mut self, key: K) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'p, T, K: Key> IntoIterator for &'p SharedVec<T, K>

Source§

type Item = (K, &'p T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'p, T, K>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, K: Key> IntoIterator for SharedVec<T, K>

Source§

type Item = (K, T)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, K>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, K = DefaultKey> !Freeze for SharedVec<T, K>

§

impl<T, K = DefaultKey> !RefUnwindSafe for SharedVec<T, K>

§

impl<T, K> Send for SharedVec<T, K>
where K: Send, T: Send,

§

impl<T, K = DefaultKey> !Sync for SharedVec<T, K>

§

impl<T, K> Unpin for SharedVec<T, K>
where K: Unpin, T: Unpin,

§

impl<T, K> UnwindSafe for SharedVec<T, K>
where K: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.