pub struct TinyVec<T> { /* private fields */ }Expand description
Ultra-compact vector using a thin pointer (8 bytes on stack).
Memory layout:
- Stack: single pointer (8 bytes) - null for empty
- Heap:
[len: u32][items: T...]- exact-sized, only allocated when non-empty
Compared to standard types:
Vec<T>: 24 bytes (ptr + len + cap), plus growth slackBox<[T]>: 16 bytes (fat pointer)TinyVec<T>: 8 bytes (thin pointer)
No spare capacity: a push reallocates in place where the allocator can, which suits collections that are mostly empty or tiny and grow one item at a time.
Implementations§
Source§impl<T> TinyVec<T>
impl<T> TinyVec<T>
pub fn is_empty(&self) -> bool
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Get a mutable slice of the items
Sourcepub fn push(&mut self, item: T)
pub fn push(&mut self, item: T)
Append an item, growing the allocation by exactly one slot (moved, never cloned).
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Keep the items matching a predicate, compacting in place and shrinking to fit.
Sourcepub fn heap_bytes(&self) -> usize
pub fn heap_bytes(&self) -> usize
Bytes this holds on the heap (header and items; nothing the items own).
Trait Implementations§
Source§impl<T> FromIterator<T> for TinyVec<T>
impl<T> FromIterator<T> for TinyVec<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<'a, T> IntoIterator for &'a TinyVec<T>
impl<'a, T> IntoIterator for &'a TinyVec<T>
Source§impl<'a, T> IntoIterator for &'a mut TinyVec<T>
impl<'a, T> IntoIterator for &'a mut TinyVec<T>
impl<T: Send> Send for TinyVec<T>
impl<T: Sync> Sync for TinyVec<T>
Auto Trait Implementations§
impl<T> Forget for TinyVec<T>
impl<T> Freeze for TinyVec<T>where
PhantomData<T>: Freeze,
impl<T> Move for TinyVec<T>
impl<T> RefUnwindSafe for TinyVec<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Unpin for TinyVec<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for TinyVec<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for TinyVec<T>where
PhantomData<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more