Struct elsa::vec::FrozenVec

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

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

Implementations§

source§

impl<T> FrozenVec<T>

source

pub fn new() -> Self

Constructs a new, empty vector.

Examples found in repository?
examples/arena.rs (line 30)
28
29
30
31
32
    fn new() -> Arena<'arena> {
        Arena {
            things: FrozenVec::new(),
        }
    }
More examples
Hide additional examples
examples/mutable_arena.rs (line 31)
29
30
31
32
33
    fn new() -> Arena<'arena> {
        Arena {
            people: FrozenVec::new(),
        }
    }
source§

impl<T> FrozenVec<T>

source

pub fn push(&self, val: T)

Appends an element to the back of the vector.

Examples found in repository?
examples/arena.rs (line 40)
34
35
36
37
38
39
40
41
42
    fn add_thing(
        &'arena self,
        name: &'static str,
        friends: Vec<ThingRef<'arena>>,
    ) -> ThingRef<'arena> {
        let idx = self.things.len();
        self.things.push(Box::new(Thing { name, friends }));
        &self.things[idx]
    }
More examples
Hide additional examples
examples/mutable_arena.rs (lines 41-45)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    fn add_person(
        &'arena self,
        name: &'static str,
        follows: Vec<PersonRef<'arena>>,
    ) -> PersonRef<'arena> {
        let idx = self.people.len();
        self.people.push(Box::new(Person {
            name,
            follows: follows.into(),
            reverse_follows: Default::default(),
        }));
        let me = &self.people[idx];
        for friend in &me.follows {
            friend.reverse_follows.push(me)
        }
        me
    }
source§

impl<T: StableDeref> FrozenVec<T>

source

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

Push, immediately getting a reference to the element

source

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

Returns a reference to an element.

source

pub unsafe fn get_unchecked(&self, index: usize) -> &T::Target

Returns a reference to an element, without doing bounds checking.

Safety

index must be in bounds, i.e. it must be less than self.len()

source§

impl<T: Copy> FrozenVec<T>

source

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

Returns a copy of an element.

source§

impl<T> FrozenVec<T>

source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Examples found in repository?
examples/arena.rs (line 39)
34
35
36
37
38
39
40
41
42
    fn add_thing(
        &'arena self,
        name: &'static str,
        friends: Vec<ThingRef<'arena>>,
    ) -> ThingRef<'arena> {
        let idx = self.things.len();
        self.things.push(Box::new(Thing { name, friends }));
        &self.things[idx]
    }
More examples
Hide additional examples
examples/mutable_arena.rs (line 40)
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    fn add_person(
        &'arena self,
        name: &'static str,
        follows: Vec<PersonRef<'arena>>,
    ) -> PersonRef<'arena> {
        let idx = self.people.len();
        self.people.push(Box::new(Person {
            name,
            follows: follows.into(),
            reverse_follows: Default::default(),
        }));
        let me = &self.people[idx];
        for friend in &me.follows {
            friend.reverse_follows.push(me)
        }
        me
    }
source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no elements.

source§

impl<T: StableDeref> FrozenVec<T>

source

pub fn first(&self) -> Option<&T::Target>

Returns the first element of the vector, or None if empty.

source

pub fn last(&self) -> Option<&T::Target>

Returns the last element of the vector, or None if empty.

source

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

Returns an iterator over the vector.

source§

impl<T: StableDeref> FrozenVec<T>

source

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

Converts the frozen vector into a plain vector.

source§

impl<T: StableDeref> FrozenVec<T>

Binary searches this sorted vector for a given element, analogous to slice::binary_search.

source

pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a T::Target) -> Ordering,

Binary searches this sorted vector with a comparator function, analogous to slice::binary_search_by.

source

pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F ) -> Result<usize, usize>
where F: FnMut(&'a T::Target) -> B, B: Ord,

Binary searches this sorted vector with a key extraction function, analogous to slice::binary_search_by_key.

source

pub fn partition_point<P>(&self, pred: P) -> usize
where P: FnMut(&T::Target) -> bool,

Returns the index of the partition point according to the given predicate (the index of the first element of the second partition), analogous to slice::partition_point.

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> 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> FromIterator<A> for FrozenVec<A>

source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = A>,

Creates a value from an iterator. Read more
source§

impl<T: StableDeref> Index<usize> for FrozenVec<T>

§

type Output = <T as Deref>::Target

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &T::Target

Performs the indexing (container[index]) operation. Read more
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: StableDeref + PartialEq> PartialEq for FrozenVec<T>
where T::Target: PartialEq,

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>

§

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

§

impl<T> UnwindSafe for FrozenVec<T>
where 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> 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.