Skip to main content

StableBTreeMap

Struct StableBTreeMap 

Source
pub struct StableBTreeMap<K: Storable + Ord + Clone, V: Storable, M: Memory = DefaultMemoryImpl> { /* private fields */ }
Expand description

Governed ordered map backed by Storage’s owned B-tree and reusable blocks.

Implementations§

Source§

impl<K: Storable + Ord + Clone, V: Storable, M: Memory> StableBTreeMap<K, V, M>

Source

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

Create a collection only in zero-page memory.

§Errors

Refuses nonempty memory, invalid encoding or capacity exhaustion before writes.

Source

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

Deliberately replace any contents in this admitted allocation.

§Errors

Returns encoding, capacity or structural admission errors.

Source

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

Load retained collection state without initializing a replacement.

§Errors

Refuses empty, foreign or corrupt memory and incompatible bounds without writing.

Source

pub fn clear(&mut self) -> Result<(), CollectionError>

Clear entries while retaining this allocation’s exclusive lease.

§Errors

Reports a poisoned owner or metadata encoding/capacity refusal.

Source

pub fn reserve_pages(self, minimum: u64) -> (Self, Result<(), RuntimeGrowError>)

Reserve a minimum virtual extent without exposing or duplicating the lease.

Returns the map on both success and ordinary growth refusal. Entries are preserved; the cached tree remains unchanged. Backing traps follow the host transaction contract.

minimum is an absolute virtual extent in 65,536-byte Wasm pages, not an entry count or additional pages. Existing extents never shrink. A request already covered performs no growth or writes. This reserves backing only: it does not promise that any particular number or encoding of entries fits. Callers own their byte/page budget and must qualify it for their codecs; internal node-layout constants are not a supported capacity contract.

Source

pub fn allocated_pages(self) -> (Self, u64)

Observe the virtual extent in 65,536-byte pages while retaining the lease.

Consumes and returns the map while retaining the exclusive lease. Observing the allocation performs no writes or growth. This is allocated extent, not free space or guaranteed entry capacity.

Source

pub fn insert(&mut self, key: K, value: V) -> Result<Option<V>, CollectionError>

Perform insert on the governed ordered map.

§Errors

Rejects encoding, decoding, structural or capacity errors before committing writes.

Source

pub fn get(&self, key: &K) -> Result<Option<V>, CollectionError>

Perform get on the governed ordered map.

§Errors

Reports structural, integrity or application decoding failures without writing.

Source

pub fn contains_key(&self, key: &K) -> Result<bool, CollectionError>

Perform contains_key on the governed ordered map.

§Errors

Reports structural, integrity or application decoding failures without writing.

Source

pub fn is_empty(&self) -> bool

Perform is_empty on the governed ordered map.

§Errors

Reports invalid region metadata or incompatible codec bounds.

Source

pub fn len(&self) -> u64

Perform len on the governed ordered map.

Source

pub fn remove(&mut self, key: &K) -> Result<Option<V>, CollectionError>

Perform remove on the governed ordered map.

§Errors

Rejects decoding or structural errors before committing removal.

Source

pub fn first_key_value(&self) -> Result<Option<(K, V)>, CollectionError>

Perform first_key_value on the governed ordered map.

§Errors

Reports invalid structure, integrity failures or application codec errors.

Source

pub fn last_key_value(&self) -> Result<Option<(K, V)>, CollectionError>

Perform last_key_value on the governed ordered map.

§Errors

Reports invalid structure, integrity failures or application codec errors.

Source

pub fn iter(&self) -> MapIter<'_, K, V, M>

Perform iter on the governed ordered map.

Source

pub fn range(&self, key_range: impl RangeBounds<K>) -> MapIter<'_, K, V, M>

Perform range on the governed ordered map.

Source

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

Perform keys on the governed ordered map.

Source

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

Perform values on the governed ordered map.

Trait Implementations§

Source§

impl<'a, K: Storable + Ord + Clone, V: Storable, M: Memory> IntoIterator for &'a StableBTreeMap<K, V, M>

Source§

type Item = <TreeIter<'a, K, V, RuntimeMemory<M>> as Iterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = TreeIter<'a, K, V, RuntimeMemory<M>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<K, V, M = Rc<RefCell<Vec<u8>>>> !Freeze for StableBTreeMap<K, V, M>

§

impl<K, V, M = Rc<RefCell<Vec<u8>>>> !RefUnwindSafe for StableBTreeMap<K, V, M>

§

impl<K, V, M = Rc<RefCell<Vec<u8>>>> !Send for StableBTreeMap<K, V, M>

§

impl<K, V, M = Rc<RefCell<Vec<u8>>>> !Sync for StableBTreeMap<K, V, M>

§

impl<K, V, M = Rc<RefCell<Vec<u8>>>> !UnwindSafe for StableBTreeMap<K, V, M>

§

impl<K, V, M> Unpin for StableBTreeMap<K, V, M>
where Tree<K, V, RuntimeMemory<M>>: Unpin,

§

impl<K, V, M> UnsafeUnpin for StableBTreeMap<K, V, M>
where Tree<K, V, RuntimeMemory<M>>: UnsafeUnpin,

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.