pub struct StableBTreeMap<K: Storable + Ord + Clone, V: Storable, M: Memory = DefaultMemoryImpl> { /* private fields */ }Expand description
StableBTreeMap
Ordered map owning one governed allocation. Stored codec and engine failures trap. Native callers must discard the runtime after a mutation panic.
Implementations§
Source§impl<K: Storable + Ord + Clone, V: Storable, M: Memory> StableBTreeMap<K, V, M>
impl<K: Storable + Ord + Clone, V: Storable, M: Memory> StableBTreeMap<K, V, M>
Sourcepub fn create(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
pub fn create(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
Sourcepub fn reset(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
pub fn reset(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
Explicitly replace this allocation’s collection image.
§Errors
Refuses initial growth before creating the map.
Sourcepub fn load(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
pub fn load(memory: RuntimeMemory<M>) -> Result<Self, CollectionError>
Load the current ordered-map format without initialization or migration.
§Errors
Refuses empty or foreign framing.
Sourcepub fn reserve_pages(self, minimum: u64) -> (Self, Result<(), RuntimeGrowError>)
pub fn reserve_pages(self, minimum: u64) -> (Self, Result<(), RuntimeGrowError>)
Reserve backing pages without promising entry capacity.
Sourcepub fn allocated_pages(self) -> (Self, u64)
pub fn allocated_pages(self) -> (Self, u64)
Observe allocated pages while retaining exclusive custody.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Insert or replace. Invalid codecs and allocation failures trap.
Sourcepub fn insert_discard(&mut self, key: K, value: V) -> bool
pub fn insert_discard(&mut self, key: K, value: V) -> bool
Insert or replace without reading or decoding the previous value payload. Returns whether an existing entry was replaced. Stored lengths and allocation metadata remain checked; callers own any required old-payload validation.
§Panics
Invalid new codecs, keys, metadata and allocation failures trap.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Test key membership without decoding values.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Remove a matching value; codec and engine failures trap.
Sourcepub fn remove_discard(&mut self, key: &K) -> bool
pub fn remove_discard(&mut self, key: &K) -> bool
Remove without reading or decoding the removed value payload. Returns whether an entry was removed. Stored lengths and allocation metadata remain checked; callers own any required old-payload validation.
§Panics
Key codec and engine failures trap.
Sourcepub fn first_key_value(&self) -> Option<(K, V)>
pub fn first_key_value(&self) -> Option<(K, V)>
First ordered key/value pair.
Sourcepub fn last_key_value(&self) -> Option<(K, V)>
pub fn last_key_value(&self) -> Option<(K, V)>
Last ordered key/value pair.
Sourcepub fn range(&self, bounds: impl RangeBounds<K>) -> MapIter<'_, K, V, M> ⓘ
pub fn range(&self, bounds: impl RangeBounds<K>) -> MapIter<'_, K, V, M> ⓘ
Iterate a bounded key range.
Sourcepub fn keys(&self) -> impl DoubleEndedIterator<Item = K> + '_
pub fn keys(&self) -> impl DoubleEndedIterator<Item = K> + '_
Iterate keys without reading value payloads.
Sourcepub fn keys_range(
&self,
bounds: impl RangeBounds<K>,
) -> impl DoubleEndedIterator<Item = K> + '_
pub fn keys_range( &self, bounds: impl RangeBounds<K>, ) -> impl DoubleEndedIterator<Item = K> + '_
Iterate bounded keys without reading value payloads.
Sourcepub fn values(&self) -> impl DoubleEndedIterator<Item = V> + '_
pub fn values(&self) -> impl DoubleEndedIterator<Item = V> + '_
Iterate decoded values.