Skip to main content

TailSeqMut

Struct TailSeqMut 

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

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

Encodes/decodes ONE element at a time directly over the account bytes; push is O(1) (write one element at the tail, bump the count). The capacity is derived from the LIVE region length, so a tail that was grown via realloc can hold more elements with no type change. push returns AccountDataTooSmall when the region is full, grow the account first.

Implementations§

Source§

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

Source

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

Overlay a write 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 is_full(&self) -> bool

Whether the sequence has reached its live capacity.

Source

pub fn remaining_capacity(&self) -> usize

Remaining element slots before a grow is required.

Source

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

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

Source

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

Overwrite the element at index in place. index must be < len.

Source

pub fn push(&mut self, value: T) -> Result<(), ProgramError>

Append value at the tail and bump the count, O(1). Returns AccountDataTooSmall when the region is at capacity (grow the account, then push again).

Source

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

Remove the element at index, moving the last element into its slot (O(1), does not preserve order). Returns the removed value.

Source

pub fn as_seq(&self) -> TailSeq<'_, T>

Borrow this cursor as a read cursor (shared reborrow).

Auto Trait Implementations§

§

impl<'a, T> !UnwindSafe for TailSeqMut<'a, T>

§

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

§

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

§

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

§

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

§

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

§

impl<'a, T> UnsafeUnpin for TailSeqMut<'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> 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.