Struct matterdb::Lazy[][src]

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

Implementations

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]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn from_access(access: T, addr: IndexAddress) -> Result<Self, AccessError>[src]

Constructs the object at the given address. Read more

fn from_root(access: T) -> Result<Self, AccessError>[src]

Constructs the object from the root of the access. Read more

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T

pub const ALIGN: usize

The alignment of pointer.

type Init = T

The type for initializers.

pub unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more

pub unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more

pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.