Struct elsa::sync::FrozenVec

source ·
pub struct FrozenVec<T> { /* private fields */ }
Expand description

Append-only threadsafe version of std::vec::Vec where insertion does not require mutable access

Implementations§

source§

impl<T> FrozenVec<T>

source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

source§

impl<T: StableDeref> FrozenVec<T>

source

pub fn new() -> Self

source

pub fn push(&self, val: T)

source

pub fn push_get(&self, val: T) -> &T::Target

Push, immediately getting a reference to the element

source

pub fn push_get_index(&self, val: T) -> usize

Push, immediately getting a an index of the element

Index can then be used with the get method

Examples
use elsa::sync::FrozenVec;

let map = FrozenVec::new();
let idx = map.push_get_index(String::from("a"));
assert_eq!(map.get(idx), Some("a"));
assert_eq!(idx, 0);
assert_eq!(map.push_get_index(String::from("b")), 1);
source

pub fn get(&self, index: usize) -> Option<&T::Target>

source

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

Returns an iterator over the vector.

source§

impl<T> FrozenVec<T>

source

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

Returns the internal vector backing this structure

Examples
use elsa::sync::FrozenVec;

let map = FrozenVec::new();
map.push("a");
map.push("b");
let tuple_vec = map.into_vec();

assert_eq!(tuple_vec, vec!["a", "b"]);

Trait Implementations§

source§

impl<T> AsMut<Vec<T>> for FrozenVec<T>

source§

fn as_mut(&mut self) -> &mut Vec<T>

Get mutable access to the underlying vector.

This is safe, as it requires a &mut self, ensuring nothing is using the ‘frozen’ contents.

source§

impl<T: Clone> Clone for FrozenVec<T>

source§

fn clone(&self) -> Self

Returns a copy 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> Debug for FrozenVec<T>

source§

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

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

impl<T> Default for FrozenVec<T>

source§

fn default() -> Self

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

impl<T> From<Vec<T>> for FrozenVec<T>

source§

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

Converts to this type from the input type.
source§

impl<'a, T: StableDeref> IntoIterator for &'a FrozenVec<T>

§

type Item = &'a <T as Deref>::Target

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> Iter<'a, T>

Creates an iterator from a value. Read more
source§

impl<T: PartialEq> PartialEq for FrozenVec<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for FrozenVec<T>

§

impl<T> Send for FrozenVec<T>
where T: Send,

§

impl<T> Sync for FrozenVec<T>
where T: Send + Sync,

§

impl<T> Unpin for FrozenVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for FrozenVec<T>

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

§

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

§

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

§

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.