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 fn new() -> Self
pub 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 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>
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 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>
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.