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: u8][items: T...]- only allocated when non-empty
Compared to standard types:
Vec<T>: 24 bytes (ptr + len + cap)Box<[T]>: 16 bytes (fat pointer)TinyVec<T>: 8 bytes (thin pointer)
Limitations:
- Max 255 items (u8 length)
- Immutable after creation (no push/pop - recreate to modify)
- Perfect for attachments/reactions which rarely change
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)where
T: Clone,
pub fn push(&mut self, item: T)where
T: Clone,
Push an item (rebuilds the entire allocation - use sparingly!)
Trait Implementations§
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> Freeze for TinyVec<T>
impl<T> RefUnwindSafe for TinyVec<T>where
T: RefUnwindSafe,
impl<T> Unpin for TinyVec<T>where
T: Unpin,
impl<T> UnsafeUnpin for TinyVec<T>
impl<T> UnwindSafe for TinyVec<T>where
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