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>
impl<T: Storable, M: Memory> StableVec<T, M>
Sourcepub fn create(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
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.
Sourcepub fn reset(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
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.
Sourcepub fn load(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
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.
Sourcepub fn set(&self, index: u64, item: &T) -> Result<(), CollectionError>
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.
Sourcepub fn push(&self, item: &T) -> Result<(), CollectionError>
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.
Sourcepub fn pop(&self) -> Result<Option<T>, CollectionError>
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.
Sourcepub fn len(&self) -> u64
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.
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = Result<T, CollectionError>> + '_
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = Result<T, CollectionError>> + '_
Decode slots lazily, returning errors without panicking on malformed data.