Skip to main content

PackedVec

Struct PackedVec 

Source
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>

Source

pub fn new() -> Self

Creates a new empty PackedVec.

Source

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.

Source

pub fn clear(&mut self)

Clears the vector, removing all elements.

Source

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.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

Source

pub fn push(&mut self, slice: &T)

Appends an item to the back of the collection.

Source

pub fn get(&self, index: usize) -> Option<&T>

Returns the slice at the given index, or None if out of bounds.

Source

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().

Source

pub fn len(&self) -> usize

Returns the number of slices in the vector.

Source

pub fn buffer_len(&self) -> usize

Returns the cumulative length of all slices in the vector in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the vector contains no slices.

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.

Source

pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a T) -> Ordering,

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.

Source

pub fn first(&self) -> Option<&T>

Returns the first element of the vector, or None if it is empty.

Source

pub fn last(&self) -> Option<&T>

Returns the last element of the vector, or None if it is empty.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the slices.

Source

pub fn drain(&mut self) -> Drain<'_, T>

Returns a draining iterator that removes all elements and yields them.

Source

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<T: ?Sized + PackedItem> Clone for PackedVec<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for PackedVec<T>
where T: Debug + ?Sized + PackedItem,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized + PackedItem> Default for PackedVec<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T> Deserialize<'de> for PackedVec<T>
where T: ToOwned + ?Sized + PackedItem + 'de, Cow<'de, T>: Deserialize<'de>,

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<U: AsRef<T>, T: ?Sized + PackedItem> Extend<U> for PackedVec<T>

Source§

fn extend<I: IntoIterator<Item = U>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<U, T: ?Sized + PackedItem, const N: usize> From<[U; N]> for PackedVec<T>
where U: AsRef<T>,

Source§

fn from(arr: [U; N]) -> Self

Converts to this type from the input type.
Source§

impl<U: AsRef<T>, T: ?Sized + PackedItem> FromIterator<U> for PackedVec<T>

Source§

fn from_iter<I: IntoIterator<Item = U>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: ?Sized + PackedItem> Hash for PackedVec<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: ?Sized + PackedItem> Index<usize> for PackedVec<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, T: ?Sized + PackedItem> IntoIterator for &'a PackedVec<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: ?Sized + PackedItem> PartialEq for PackedVec<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for PackedVec<T>
where T: Serialize + ?Sized + PackedItem,

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: ?Sized + PackedItem> Eq for PackedVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for PackedVec<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for PackedVec<T>
where T: ?Sized,

§

impl<T> Send for PackedVec<T>
where T: ?Sized,

§

impl<T> Sync for PackedVec<T>
where T: ?Sized,

§

impl<T> Unpin for PackedVec<T>
where T: ?Sized,

§

impl<T> UnsafeUnpin for PackedVec<T>
where T: ?Sized,

§

impl<T> UnwindSafe for PackedVec<T>
where T: ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,