Skip to main content

StableVec

Struct StableVec 

Source
pub struct StableVec<T: Storable, M: Memory = DefaultMemoryImpl> { /* private fields */ }
Expand description

StableVec

Indexed stable values in fixed-stride slots. Values require a finite bound. Each slot protects its index, length and payload with an integrity checksum. Native interrupted writes poison the owner and may damage retained bytes.

Implementations§

Source§

impl<T: Storable, M: Memory> StableVec<T, M>

Source

pub fn create(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>

Create only in an empty allocation. Invalid bounds refuse before writes.

§Errors

Rejects nonempty memory, invalid encoding/bounds or capacity refusal before writing.

Source

pub fn reset(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>

Explicitly discard previous contents in this allocation.

§Errors

Rejects invalid encoding/bounds or capacity refusal before replacing contents.

Source

pub fn load(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>

Read and validate the current root without initializing or writing.

§Errors

Rejects foreign, corrupt or oversized records and incompatible codec bounds.

Source

pub fn get(&self, index: u64) -> Result<Option<T>, CollectionError>

Decode an indexed value, checking length and checksum before its codec.

§Errors

Reports structural, integrity or application decoding failures without writing.

§Panics

Propagates backing panics or a faulty caller codec.

Source

pub fn set(&self, index: u64, item: &T) -> Result<(), CollectionError>

Replace an existing value. Encoding and bounds admission precede writes.

§Errors

Rejects invalid indices, encoding, bounds or capacity refusal before writes.

Source

pub fn push(&self, item: &T) -> Result<(), CollectionError>

Append after reserving capacity; publish the new length last.

§Errors

Rejects invalid encoding, bounds, arithmetic overflow or capacity refusal before writes.

Source

pub fn pop(&self) -> Result<Option<T>, CollectionError>

Remove the final value, retaining allocated capacity for reuse.

§Errors

Rejects integrity, decoding or structural errors before changing the length.

Source

pub fn len(&self) -> u64

Number of committed slots. A poisoned owner must be dropped.

§Panics

A poisoned owner must be dropped before further observation.

Source

pub fn is_empty(&self) -> bool

Whether the vector has no values.

Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = Result<T, CollectionError>> + '_

Decode slots lazily, returning errors without panicking on malformed data.

Auto Trait Implementations§

§

impl<T, M = Rc<RefCell<Vec<u8>>>> !Freeze for StableVec<T, M>

§

impl<T, M = Rc<RefCell<Vec<u8>>>> !RefUnwindSafe for StableVec<T, M>

§

impl<T, M = Rc<RefCell<Vec<u8>>>> !Send for StableVec<T, M>

§

impl<T, M = Rc<RefCell<Vec<u8>>>> !Sync for StableVec<T, M>

§

impl<T, M = Rc<RefCell<Vec<u8>>>> !UnwindSafe for StableVec<T, M>

§

impl<T, M> Unpin for StableVec<T, M>

§

impl<T, M> UnsafeUnpin for StableVec<T, M>

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.