pub struct PackedVec<T: ?Sized + PackedItem> { /* private fields */ }Expand description
A packed vector that stores slices of an element type in a single contiguous buffer.
This behaves somewhat like a Vec<Box<[T]>> or Vec<Vec<T>>, but allows
for better memory locality and fewer allocations by storing all elements
in one Vec<T::Item>.
Implementations§
Source§impl<T: ?Sized + PackedItem> PackedVec<T>
impl<T: ?Sized + PackedItem> PackedVec<T>
Sourcepub fn with_capacity(element_capacity: usize, buffer_capacity: usize) -> Self
pub fn with_capacity(element_capacity: usize, buffer_capacity: usize) -> Self
Creates a new PackedVec with the specified capacities.
The element_capacity argument specifies the number of slices that can be
stored without reallocating the offsets vector. The buffer_capacity
argument specifies the cumulative length of slices that can be stored
without reallocating the data vector.
Sourcepub fn from_slice<U: AsRef<T>>(slices: &[U]) -> Self
pub fn from_slice<U: AsRef<T>>(slices: &[U]) -> Self
Creates a new PackedVec from a slice of element slices, pre-allocating
the required capacity.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns the slice at the given index, or None if out of bounds.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &T
pub unsafe fn get_unchecked(&self, index: usize) -> &T
Returns a reference to the slice at the given index without bounds checking.
§Safety
The index must be less than self.len().
Sourcepub fn buffer_len(&self) -> usize
pub fn buffer_len(&self) -> usize
Returns the cumulative length of all slices in the vector in bytes.
Sourcepub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
pub fn binary_search(&self, x: &T) -> Result<usize, usize>where
T: Ord,
Binary searches this sorted vector for a given element.
If the value is found then Result::Ok is returned, containing the index
of the matching element. If there are multiple matches, then any one of the
matches could be returned.
If the value is not found then Result::Err is returned, containing the
index where a matching element could be inserted while maintaining sorted
order.
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 for a given element.
If the value is found then Result::Ok is returned, containing the index
of the matching element. If there are multiple matches, then any one of the
matches could be returned.
If the value is not found then Result::Err is returned, containing the
index where a matching element could be inserted while maintaining sorted
order.
Sourcepub fn first(&self) -> Option<&T>
pub fn first(&self) -> Option<&T>
Returns the first element of the vector, or None if it is empty.
Sourcepub fn last(&self) -> Option<&T>
pub fn last(&self) -> Option<&T>
Returns the last element of the vector, or None if it is empty.
Sourcepub fn drain(&mut self) -> Drain<'_, T>
pub fn drain(&mut self) -> Drain<'_, T>
Returns a draining iterator that removes all elements and yields them.
Sourcepub fn range<R: RangeBounds<usize>>(&self, range: R) -> Iter<'_, T>
pub fn range<R: RangeBounds<usize>>(&self, range: R) -> Iter<'_, T>
Returns an iterator over a sub-range of slices in the vector.
The bounds must be usize bounds (representing indices).
If bounds are outside the vector length or inverted, they will be clipped.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for PackedVec<T>
impl<'de, T> Deserialize<'de> for PackedVec<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<U: AsRef<T>, T: ?Sized + PackedItem> Extend<U> for PackedVec<T>
impl<U: AsRef<T>, T: ?Sized + PackedItem> Extend<U> for PackedVec<T>
Source§fn extend<I: IntoIterator<Item = U>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = U>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)