pub struct InlineVec<T, const N: usize>(/* private fields */);Expand description
A wrapper around a Vec<T> that lives on the stack if it is small enough.
Implementations§
Source§impl<T, const N: usize> InlineVec<T, N>
impl<T, const N: usize> InlineVec<T, N>
Sourcepub fn is_heap_allocated(&self) -> bool
pub fn is_heap_allocated(&self) -> bool
Checks whether this vector is allocated on the heap
Sourcepub unsafe fn inline_parts_mut(
&mut self,
) -> Option<(&mut [MaybeUninit<T>; N], usize)>
pub unsafe fn inline_parts_mut( &mut self, ) -> Option<(&mut [MaybeUninit<T>; N], usize)>
If self is inlined, this returns the underlying raw parts that make up this InlineVec.
Only the first .1 elements are initialized.
fn mutate<T, const N: usize>(values: &mut tl::inline::vec::InlineVec<T, N>) {
let _ = values.inline_parts_mut(); // an unsafe call is required
}§Safety
Before the borrow ends, the initialized prefix must contain valid, uniquely
owned values of the element type. Replacing a slot with uninitialized data,
duplicating an owner or dropping it without replacing it violates this contract.
Prefer get_mut or typed mutable access instead.
Sourcepub fn push(&mut self, value: T) -> Result<(), ParseError>
pub fn push(&mut self, value: T) -> Result<(), ParseError>
Inserts a new element into the vector
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns a reference to the value at the given index
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the value at the given index
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes the last element and returns it, or None if it is empty.
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Removes an element at a given index
§Panics
Just like Vec::remove, this method will panic if the index is out of bounds.
Sourcepub fn iter(&self) -> InlineVecIter<'_, T, N> ⓘ
pub fn iter(&self) -> InlineVecIter<'_, T, N> ⓘ
Returns an iterator over the elements of this vector
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice to the contents of this vector.