Skip to main content

TailSeq

Struct TailSeq 

Source
pub struct TailSeq<'a, T: SeqElement> { /* private fields */ }
Expand description

Streaming read cursor over a Seq<T> tail region.

Borrows the tail-region bytes ([count:u32][elems...]) and decodes ONE element per get / iterator step; it never builds a [T; N]. Cheap to construct and copy.

Implementations§

Source§

impl<'a, T: SeqElement> TailSeq<'a, T>

Source

pub fn from_region(region: &'a [u8]) -> Result<Self, ProgramError>

Overlay a read cursor on region (the tail bytes starting at the count prefix). Rejects a region too small for the prefix, or a stored count exceeding the region’s capacity (corrupt tail).

Source

pub fn len(&self) -> u32

Number of live elements (the u32 count prefix).

Source

pub fn is_empty(&self) -> bool

Whether the sequence is empty.

Source

pub fn capacity(&self) -> usize

Live element capacity from the region length: (len - 4) / STRIDE.

Source

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

Decode the element at index (one element, no full-tail decode).

Source

pub fn iter(&self) -> TailSeqIter<'a, T> ⓘ

Iterate the live elements, decoding one at a time. Each item is a Result because a corrupt slot can fail to decode (e.g. a bool byte outside {0, 1}); a well-formed Seq yields only Ok.

Trait Implementations§

Source§

impl<'a, T: Clone + SeqElement> Clone for TailSeq<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Copy + SeqElement> Copy for TailSeq<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for TailSeq<'a, T>
where PhantomData<T>: Freeze,

§

impl<'a, T> RefUnwindSafe for TailSeq<'a, T>

§

impl<'a, T> Send for TailSeq<'a, T>
where PhantomData<T>: Send,

§

impl<'a, T> Sync for TailSeq<'a, T>
where PhantomData<T>: Sync,

§

impl<'a, T> Unpin for TailSeq<'a, T>
where PhantomData<T>: Unpin,

§

impl<'a, T> UnsafeUnpin for TailSeq<'a, T>

§

impl<'a, T> UnwindSafe for TailSeq<'a, T>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.