pub struct MapIndex<T, K, V> { /* fields omitted */ }
A map of keys and values. Access to the elements of this map is obtained using the keys.
MapIndex
requires that keys implement the StorageKey
trait and values implement
the StorageValue
trait.
Creates a new index representation based on the name and storage view.
Storage view can be specified as &Snapshot
or &mut Fork
. In the first case, only
immutable methods are available. In the second case, both immutable and mutable methods are
available.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
Creates a new index representation based on the name, index ID in family
and storage view.
Storage view can be specified as &Snapshot
or &mut Fork
. In the first case, only
immutable methods are available. In the second case, both immutable and mutable methods are
available.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let index_id = vec![01];
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new_in_family(name, &index_id, &snapshot);
Returns a value corresponding to the key.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = MapIndex::new(name, &mut fork);
assert!(index.get(&1).is_none());
index.put(&1, 2);
assert_eq!(Some(2), index.get(&1));
Returns true
if the map contains a value corresponding to the specified key.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = MapIndex::new(name, &mut fork);
assert!(!index.contains(&1));
index.put(&1, 2);
assert!(index.contains(&1));
Returns an iterator over the entries of the map in ascending order. The iterator element
type is (K, V).
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for v in index.iter() {
println!("{:?}", v);
}
Returns an iterator over the keys of a map in ascending order. The iterator element
type is K.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for key in index.keys() {
println!("{}", key);
}
Returns an iterator over the values of a map in ascending order of keys. The iterator
element type is V.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for val in index.values() {
println!("{}", val);
}
Returns an iterator over the entries of a map in ascending order starting from the
specified key. The iterator element type is (K, V).
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for v in index.iter_from(&2) {
println!("{:?}", v);
}
Returns an iterator over the keys of a map in ascending order starting from the
specified key. The iterator element type is K.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for key in index.keys_from(&2) {
println!("{}", key);
}
Returns an iterator over the values of a map in ascending order of keys starting from the
specified key. The iterator element type is V.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: MapIndex<_, u8, u8> = MapIndex::new(name, &snapshot);
for val in index.values_from(&2) {
println!("{}", val);
}
pub fn put(&mut self, key: &K, value: V) | [src] |
Inserts a key-value pair into a map.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = MapIndex::new(name, &mut fork);
index.put(&1, 2);
assert!(index.contains(&1));
Removes a key from a map.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = MapIndex::new(name, &mut fork);
index.put(&1, 2);
assert!(index.contains(&1));
index.remove(&1);
assert!(!index.contains(&1));
Clears a map, removing all entries.
Currently, this method is not optimized to delete a large set of data. During the execution of
this method, the amount of allocated memory is linearly dependent on the number of elements
in the index.
use exonum::storage::{MemoryDB, Database, MapIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = MapIndex::new(name, &mut fork);
index.put(&1, 2);
assert!(index.contains(&1));
index.clear();
assert!(!index.contains(&1));
type Item = (K::Owned, V)
The type of the elements being iterated over.
type IntoIter = MapIndexIter<'a, K, V>
Which kind of iterator are we turning this into?
Formats the value using the given formatter. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static