Struct pal::HeaderVec

source ·
pub struct HeaderVec<T, U: FixedArray> { /* private fields */ }
Expand description

Implements a Vec-like type for building structures with a fixed-sized prefix before a dynamic number of elements.

To avoid allocations in common cases, the header and elements are stored internally without allocating until the element count would exceed the statically determined capacity.

Only a small portion of the Vec interface is supported. Additional methods can be added as needed.

The data managed by this type must be Copy. This simplifies the resource management and should be sufficient for most use cases.

§Example

#[derive(Copy, Clone)]
struct Header { x: u32 }
let mut v = HeaderVec::<Header, [u8; 10]>::new(Header{ x: 1234 });
v.push(5);
v.push(6);
assert_eq!(v.x, 1234);
assert_eq!(&v[..], &[5, 6]);

Implementations§

source§

impl<T: Copy, U: FixedArray> HeaderVec<T, U>

source

pub fn new(head: T) -> Self

Constructs a new HeaderVec with a header of head and no tail elements.

source

pub fn with_capacity(head: T, cap: usize) -> Self

Constructs a new HeaderVec with a header of head and no tail elements, but with a dynamically allocated capacity for cap elements.

source

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

source

pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<U::Element>]

Returns the remaining spare capacity of the tail as a slice of MaybeUninit<U::Element>.

The returned slice can be used to fill the tail with data before marking the data as initialized using `Self::set_len.

source

pub fn push(&mut self, val: U::Element)

Pushes a tail element, reallocating if necessary.

source

pub fn extend_from_slice(&mut self, other: &[U::Element])

Extends the tail elements from the given slice.

source

pub fn as_ptr(&self) -> *const T

Retrieves a pointer to the head. The tail is guaranteed to immediately after the head (with appropriate padding).

source

pub fn as_mut_ptr(&mut self) -> *mut T

Retrieves a mutable pointer to the head. The tail is guaranteed to immediately after the head (with appropriate padding).

source

pub fn as_slice(&self) -> &[U::Element]

Returns a slice of the tail elements.

source

pub fn as_mut_slice(&mut self) -> &mut [U::Element]

Returns a mutable slice of the tail elements.

source

pub fn len(&self) -> usize

Returns the number of tail elements.

source

pub fn capacity(&self) -> usize

source

pub fn is_empty(&self) -> bool

Returns true if there are no tail elements.

source

pub fn clear(&mut self)

Sets the number of tail elements to 0.

source

pub fn truncate(&mut self, len: usize)

Truncates the tail to len elements. Has no effect if there are already fewer than len tail elements.

source

pub unsafe fn set_len(&mut self, len: usize)

Sets the number of tail elements.

Panics if len is greater than the capacity.

§Safety

The caller must ensure that all len elements have been initialized.

source

pub fn total_byte_len(&self) -> usize

Returns the total contiguous byte length of the structure, including both the head and tail elements.

source

pub fn total_byte_capacity(&self) -> usize

Returns the total contiguous byte length of the structure, including both the head and tail elements, including the tail’s capacity.

source

pub fn iter(&self) -> Iter<'_, U::Element>

Returns an iterator of the tail elements.

source

pub fn iter_mut(&mut self) -> IterMut<'_, U::Element>

Returns a mutable iterator of the tail elements.

Trait Implementations§

source§

impl<T: Debug, U: Debug + FixedArray> Debug for HeaderVec<T, U>

source§

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

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

impl<T: Copy + Default, U: FixedArray> Default for HeaderVec<T, U>

source§

fn default() -> Self

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

impl<T, U: FixedArray> Deref for HeaderVec<T, U>

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T, U: FixedArray> DerefMut for HeaderVec<T, U>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T: Copy, U: FixedArray> Extend<<U as FixedArray>::Element> for HeaderVec<T, U>

source§

fn extend<I: IntoIterator<Item = U::Element>>(&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<T: Copy, U: FixedArray, I: SliceIndex<[U::Element]>> Index<I> for HeaderVec<T, U>

source§

type Output = <I as SliceIndex<[<U as FixedArray>::Element]>>::Output

The returned type after indexing.
source§

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

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

impl<T: Copy, U: FixedArray, I: SliceIndex<[U::Element]>> IndexMut<I> for HeaderVec<T, U>

source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

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

Auto Trait Implementations§

§

impl<T, U> Freeze for HeaderVec<T, U>
where T: Freeze, U: Freeze,

§

impl<T, U> RefUnwindSafe for HeaderVec<T, U>

§

impl<T, U> Send for HeaderVec<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for HeaderVec<T, U>
where T: Sync, U: Sync,

§

impl<T, U> Unpin for HeaderVec<T, U>
where T: Unpin, U: Unpin,

§

impl<T, U> UnwindSafe for HeaderVec<T, U>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more