[][src]Struct exonum::storage::map_index::MapIndex

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.

Methods

impl<T, K, V> MapIndex<T, K, V> where
    T: AsRef<dyn Snapshot>,
    K: StorageKey,
    V: StorageValue
[src]

pub fn new<S: AsRef<str>>(index_name: S, view: T) -> Self
[src]

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.

Examples

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);

pub fn new_in_family<S: AsRef<str>, I: StorageKey>(
    family_name: S,
    index_id: &I,
    view: T
) -> Self
[src]

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.

Examples

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);

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: StorageKey
[src]

Returns a value corresponding to the key.

Examples

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));

pub fn contains<Q: ?Sized>(&self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: StorageKey
[src]

Returns true if the map contains a value corresponding to the specified key.

Examples

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));

Important traits for MapIndexIter<'a, K, V>
pub fn iter(&self) -> MapIndexIter<K, V>
[src]

Returns an iterator over the entries of the map in ascending order. The iterator element type is (K, V).

Examples

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);
}

Important traits for MapIndexKeys<'a, K>
pub fn keys(&self) -> MapIndexKeys<K>
[src]

Returns an iterator over the keys of a map in ascending order. The iterator element type is K.

Examples

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);
}

Important traits for MapIndexValues<'a, V>
pub fn values(&self) -> MapIndexValues<V>
[src]

Returns an iterator over the values of a map in ascending order of keys. The iterator element type is V.

Examples

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);
}

Important traits for MapIndexIter<'a, K, V>
pub fn iter_from<Q: ?Sized>(&self, from: &Q) -> MapIndexIter<K, V> where
    K: Borrow<Q>,
    Q: StorageKey
[src]

Returns an iterator over the entries of a map in ascending order starting from the specified key. The iterator element type is (K, V).

Examples

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);
}

Important traits for MapIndexKeys<'a, K>
pub fn keys_from<Q: ?Sized>(&self, from: &Q) -> MapIndexKeys<K> where
    K: Borrow<Q>,
    Q: StorageKey
[src]

Returns an iterator over the keys of a map in ascending order starting from the specified key. The iterator element type is K.

Examples

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);
}

Important traits for MapIndexValues<'a, V>
pub fn values_from<Q: ?Sized>(&self, from: &Q) -> MapIndexValues<V> where
    K: Borrow<Q>,
    Q: StorageKey
[src]

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.

Examples

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);
}

impl<'a, K, V> MapIndex<&'a mut Fork, K, V> where
    K: StorageKey,
    V: StorageValue
[src]

pub fn put(&mut self, key: &K, value: V)
[src]

Inserts a key-value pair into a map.

Examples

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));

pub fn remove<Q: ?Sized>(&mut self, key: &Q) where
    K: Borrow<Q>,
    Q: StorageKey
[src]

Removes a key from a map.

Examples

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));

pub fn clear(&mut self)
[src]

Clears a map, removing all entries.

Notes

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.

Examples

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));

Trait Implementations

impl<'a, T, K, V> IntoIterator for &'a MapIndex<T, K, V> where
    T: AsRef<dyn Snapshot>,
    K: StorageKey,
    V: StorageValue
[src]

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?

impl<T: Debug, K: Debug, V: Debug> Debug for MapIndex<T, K, V>
[src]

Auto Trait Implementations

impl<T, K, V> Send for MapIndex<T, K, V> where
    K: Send,
    T: Send,
    V: Send

impl<T, K, V> Sync for MapIndex<T, K, V> where
    K: Sync,
    T: Sync,
    V: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T> Erased for T

impl<T> Same for T

type Output = T

Should always be Self