Trait orx_fixed_vec::prelude::PinnedVec
source · pub trait PinnedVec<T> {
Show 15 methods
// Required methods
fn capacity(&self) -> usize;
fn clear(&mut self);
fn extend_from_slice(&mut self, other: &[T])
where T: Clone;
fn get(&self, index: usize) -> Option<&T>;
fn get_mut(&mut self, index: usize) -> Option<&mut T>;
unsafe fn get_unchecked(&self, index: usize) -> &T;
unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T;
fn insert(&mut self, index: usize, element: T);
fn is_empty(&self) -> bool;
fn len(&self) -> usize;
fn pop(&mut self) -> Option<T>;
fn push(&mut self, value: T);
fn remove(&mut self, index: usize) -> T;
fn partial_eq<S>(&self, other: S) -> bool
where S: AsRef<[T]>,
T: PartialEq<T>;
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
where T: Debug;
}
Expand description
A vector of elements of T which differs from the std::vec::Vec
by the following feature:
- memory location of an element already pushed to the collection never changes and remains valid unless:
- the vector is
drop
ped, - the vector is
clear
ed,resize
d ortruncate
d, - any element is
insert
ed into the vector, - any element is
remove
d orpop
ped from the vector.
- the vector is
Or, more briefly, push
ing or extend
ing the vector does not change memory locations
of already added elements, and hence, the corresponding references remain valid.
Safety
This trait can be considered as a marker trait: its methods are relevant for the useful ‘vec’-related side of the trait, rather than the pinned side. The implementing struct must guarantee that pushing or extending the vector does not cause the memory locations of already added elements to change.
Required Methods§
sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the total number of elements the vector can hold without reallocating.
sourcefn clear(&mut self)
fn clear(&mut self)
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
sourcefn extend_from_slice(&mut self, other: &[T])where
T: Clone,
fn extend_from_slice(&mut self, other: &[T])where T: Clone,
Clones and appends all elements in a slice to the Vec.
Iterates over the slice other, clones each element, and then appends it to this Vec. The other slice is traversed in-order.
Note that this function is same as extend except that it is specialized to work with slices instead. If and when Rust gets specialization this function will likely be deprecated (but still available).
sourcefn get(&self, index: usize) -> Option<&T>
fn get(&self, index: usize) -> Option<&T>
Returns a reference to an element with the given index
,
returns None if the index is out of bounds.
sourcefn get_mut(&mut self, index: usize) -> Option<&mut T>
fn get_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to an element with the given index
,
returns None if the index is out of bounds.
sourceunsafe fn get_unchecked(&self, index: usize) -> &T
unsafe fn get_unchecked(&self, index: usize) -> &T
Returns a reference to an element or subslice, without doing bounds checking.
For a safe alternative see [get
].
Safety
Calling this method with an out-of-bounds index is [undefined behavior] even if the resulting reference is not used.
sourceunsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
Returns a mutable reference to an element or subslice, without doing bounds checking.
For a safe alternative see [get_mut
].
Safety
Calling this method with an out-of-bounds index is [undefined behavior] even if the resulting reference is not used.
sourcefn insert(&mut self, index: usize, element: T)
fn insert(&mut self, index: usize, element: T)
Inserts an element at position index within the vector, shifting all elements after it to the right.
Panics
Panics if index >= len
.
sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of elements in the vector, also referred to as its ‘length’.
sourcefn pop(&mut self) -> Option<T>
fn pop(&mut self) -> Option<T>
Removes the last element from a vector and returns it, or None if it is empty.
sourcefn remove(&mut self, index: usize) -> T
fn remove(&mut self, index: usize) -> T
Removes and returns the element at position index within the vector, shifting all elements after it to the left.
Panics
Panics if index is out of bounds.