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>
impl<T> FrozenVec<T>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Constructs a new, empty vector.
Examples found in repository?
More examples
Source§impl<T> FrozenVec<T>
impl<T> FrozenVec<T>
Sourcepub fn push(&self, val: T)
pub fn push(&self, val: T)
Appends an element to the back of the vector.
Examples found in repository?
More examples
35 fn add_person(
36 &'arena self,
37 name: &'static str,
38 follows: Vec<PersonRef<'arena>>,
39 ) -> PersonRef<'arena> {
40 let idx = self.people.len();
41 self.people.push(Box::new(Person {
42 name,
43 follows: follows.into(),
44 reverse_follows: Default::default(),
45 }));
46 let me = &self.people[idx];
47 for friend in &me.follows {
48 friend.reverse_follows.push(me)
49 }
50 me
51 }
Source§impl<T: StableDeref> FrozenVec<T>
impl<T: StableDeref> FrozenVec<T>
Sourcepub fn push_get(&self, val: T) -> &T::Target
pub fn push_get(&self, val: T) -> &T::Target
Push, immediately getting a reference to the element
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &T::Target
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> FrozenVec<T>
impl<T> FrozenVec<T>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the vector.
Examples found in repository?
More examples
35 fn add_person(
36 &'arena self,
37 name: &'static str,
38 follows: Vec<PersonRef<'arena>>,
39 ) -> PersonRef<'arena> {
40 let idx = self.people.len();
41 self.people.push(Box::new(Person {
42 name,
43 follows: follows.into(),
44 reverse_follows: Default::default(),
45 }));
46 let me = &self.people[idx];
47 for friend in &me.follows {
48 friend.reverse_follows.push(me)
49 }
50 me
51 }
Source§impl<T: StableDeref> FrozenVec<T>
impl<T: StableDeref> FrozenVec<T>
Source§impl<T: StableDeref> FrozenVec<T>
impl<T: StableDeref> FrozenVec<T>
Source§impl<T: StableDeref> FrozenVec<T>
impl<T: StableDeref> FrozenVec<T>
Sourcepub fn binary_search(&self, x: &T::Target) -> Result<usize, usize>
pub fn binary_search(&self, x: &T::Target) -> Result<usize, usize>
Binary searches this sorted vector for a given element, analogous to slice::binary_search.
Sourcepub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Binary searches this sorted vector with a comparator function, analogous to slice::binary_search_by.
Sourcepub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Binary searches this sorted vector with a key extraction function, analogous to slice::binary_search_by_key.
Sourcepub fn partition_point<P>(&self, pred: P) -> usize
pub fn partition_point<P>(&self, pred: P) -> usize
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.