[][src]Struct exonum_merkledb::Lazy

pub struct Lazy<T, I> { /* fields omitted */ }

Lazily initialized object in the database.

Unlike eagerly initialized objects, lazy ones are not accessed until a get() method is called; thus, construction of a lazy object is cheap. This can be used to improve performance of a database object, some components of which are rarely accessed.

Note that Groups are already lazy, so it does not make sense to wrap a one into Lazy<_> (although this is technically possible).

Examples

let db = TemporaryDB::new();
let fork = db.fork();
{
    let lazy: Lazy<_, ListIndex<_, String>> =
        Lazy::from_access(&fork, "lazy_list".into()).unwrap();
    lazy.get().push("!".to_owned());
    assert_eq!(lazy.get().len(), 1);
}
// List can then be accessed eagerly.
assert_eq!(
    fork.get_list::<_, String>("lazy_list").get(0),
    Some("!".to_owned())
);

Methods

impl<T, I> Lazy<T, I> where
    T: Access,
    I: FromAccess<T>, 
[src]

pub fn get(&self) -> I[src]

Gets the object from the database.

Panics

Panics if the object cannot be restored.

pub fn try_get(&self) -> Result<I, AccessError>[src]

Tries to restore the object from the database.

Trait Implementations

impl<T: Debug, I: Debug> Debug for Lazy<T, I>[src]

impl<T, I> FromAccess<T> for Lazy<T, I> where
    T: Access,
    I: FromAccess<T>, 
[src]

Auto Trait Implementations

impl<T, I> RefUnwindSafe for Lazy<T, I> where
    I: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, I> Send for Lazy<T, I> where
    I: Send,
    T: Send

impl<T, I> Sync for Lazy<T, I> where
    I: Sync,
    T: Sync

impl<T, I> Unpin for Lazy<T, I> where
    I: Unpin,
    T: Unpin

impl<T, I> UnwindSafe for Lazy<T, I> where
    I: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,