pub struct StableVec<T: Storable, M: Memory = DefaultMemoryImpl> { /* private fields */ }Expand description
Governed upstream Vec; initialization and failures follow upstream contracts.
Implementations§
Source§impl<T: Storable, M: Memory> StableVec<T, M>
impl<T: Storable, M: Memory> StableVec<T, M>
Sourcepub fn new(memory: RuntimeMemory<M>) -> Self
pub fn new(memory: RuntimeMemory<M>) -> Self
Create a new collection, replacing any prior collection in the selected memory. This is destructive even when a valid collection already exists.
§Panics
Panics on insufficient memory or codec/backing failure.
Sourcepub fn init(memory: RuntimeMemory<M>) -> Self
pub fn init(memory: RuntimeMemory<M>) -> Self
Open a valid retained collection, or create one in zero-page memory.
§Panics
Panics for foreign magic, unsupported layout, incompatible element bounds, insufficient memory or codec/backing failure. Foreign memory is not reset.
Sourcepub fn get(&self, index: u64) -> Option<T>
pub fn get(&self, index: u64) -> Option<T>
Delegates to upstream Vec::get with the governed allocation.
Sourcepub fn set(&self, index: u64, item: &T)
pub fn set(&self, index: u64, item: &T)
Delegates to upstream Vec::set with the governed allocation.
Sourcepub fn reset(self) -> Self
pub fn reset(self) -> Self
Reset to an empty vector while retaining this allocation’s exclusive lease.
Existing payload bytes follow upstream Vec::new semantics.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Delegates to upstream Vec::is_empty with the governed allocation.
Sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
pub fn iter(&self) -> impl DoubleEndedIterator<Item = T> + '_
Delegates to upstream Vec::iter with the governed allocation.