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]
T: AsRef<Snapshot>,
V: StorageValue,
pub fn new<S: AsRef<str>>(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, Entry}; let db = MemoryDB::new(); let name = "name"; let snapshot = db.snapshot(); let index: Entry<_, u8> = Entry::new(name, &snapshot);
pub fn get(&self) -> Option<V>
[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());
pub fn exists(&self) -> bool
[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());
pub fn hash(&self) -> Hash
[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]
V: StorageValue,
pub fn set(&mut self, value: V)
[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());
pub fn remove(&mut self)
[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());