Skip to main content

StoreRange

Trait StoreRange 

Source
pub trait StoreRange<K, V>: Store<K, V>
where K: Key, V: Value,
{ type Range<'a>: Iterator<Item = (&'a K, &'a V)> where Self: 'a; // Required method fn range<R>(&self, range: R) -> Self::Range<'_> where R: RangeBounds<K>; }
Expand description

Immutable store that is iterable over a range.

This trait extends Store, adding iteration capabilities as a further requirement, so a store can enumerate its items over a given range.

§Examples

use std::collections::BTreeMap;
use zrx_store::{StoreMut, StoreRange};

// Create store and initial state
let mut store = BTreeMap::new();
store.insert("a", 42);
store.insert("b", 84);

// Create iterator over the store
for (key, value) in store.range("b"..) {
    println!("{key}: {value}");
}

Required Associated Types§

Source

type Range<'a>: Iterator<Item = (&'a K, &'a V)> where Self: 'a

Required Methods§

Source

fn range<R>(&self, range: R) -> Self::Range<'_>
where R: RangeBounds<K>,

Creates an iterator over a range of items of the store.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<K, V> StoreRange<K, V> for BTreeMap<K, V>
where K: Key, V: Value,

Source§

fn range<R>(&self, range: R) -> <BTreeMap<K, V> as StoreRange<K, V>>::Range<'_>
where R: RangeBounds<K>,

Creates an iterator over a range of items in a store.

§Examples
use std::collections::BTreeMap;
use zrx_store::{StoreMut, StoreRange};

// Create store and initial state
let mut store = BTreeMap::new();
store.insert("a", 42);
store.insert("b", 84);

// Create iterator over the store
for (key, value) in store.range("b"..) {
    println!("{key}: {value}");
}
Source§

type Range<'a> = Range<'a, K, V> where BTreeMap<K, V>: 'a

Implementors§