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>
impl<'a, T: SeqElement> TailSeqMut<'a, T>
Sourcepub fn from_region(region: &'a mut [u8]) -> Result<Self, ProgramError>
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).
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Live element capacity from the region length: (len - 4) / STRIDE.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
Remaining element slots before a grow is required.
Sourcepub fn get(&self, index: usize) -> Result<T, ProgramError>
pub fn get(&self, index: usize) -> Result<T, ProgramError>
Decode the element at index (one element, no full-tail decode).
Sourcepub fn set(&mut self, index: usize, value: T) -> Result<(), ProgramError>
pub fn set(&mut self, index: usize, value: T) -> Result<(), ProgramError>
Overwrite the element at index in place. index must be < len.
Sourcepub fn push(&mut self, value: T) -> Result<(), ProgramError>
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).
Sourcepub fn swap_remove(&mut self, index: usize) -> Result<T, ProgramError>
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.