Struct exonum::storage::Entry [] [src]

pub struct Entry<T, V> { /* fields omitted */ }

An index that may only contain one element.

A value should implement StorageValue trait.

Methods

impl<T, V> Entry<T, V> where
    T: AsRef<Snapshot>,
    V: StorageValue
[src]

[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, Entry};

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: Entry<_, u8> = Entry::new(name, &snapshot);

[src]

Returns a value of the entry or None if does not exist.

Examples

use exonum::storage::{MemoryDB, Database, Entry};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = Entry::new(name, &mut fork);
assert_eq!(None, index.get());

index.set(10);
assert_eq!(Some(10), index.get());

[src]

Returns true if a value of the entry exists.

Examples

use exonum::storage::{MemoryDB, Database, Entry};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = Entry::new(name, &mut fork);
assert!(!index.exists());

index.set(10);
assert!(index.exists());

[src]

Returns hash of the entry or default hash value if does not exist.

Examples

use exonum::storage::{MemoryDB, Database, Entry};
use exonum::crypto::{self, Hash};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = Entry::new(name, &mut fork);
assert_eq!(Hash::default(), index.hash());

let value = 10;
index.set(value);
assert_eq!(crypto::hash(&[value]), index.hash());

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

[src]

Changes a value of the entry.

Examples

use exonum::storage::{MemoryDB, Database, Entry};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = Entry::new(name, &mut fork);

index.set(10);
assert_eq!(Some(10), index.get());

[src]

Removes a value of the entry.

Examples

use exonum::storage::{MemoryDB, Database, Entry};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = Entry::new(name, &mut fork);

index.set(10);
assert_eq!(Some(10), index.get());

index.remove();
assert_eq!(None, index.get());

Trait Implementations

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

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T, V> Send for Entry<T, V> where
    T: Send,
    V: Send

impl<T, V> Sync for Entry<T, V> where
    T: Sync,
    V: Sync