pub struct Db<Storage> { /* private fields */ }Expand description
The central database object to manage and cache incremental computations.
To use this, a type implementing Storage is required to be provided.
See the documentation for impl_storage!.
Implementations§
Source§impl<S> Db<S>
impl<S> Db<S>
Sourcepub fn with_storage(storage: S) -> Self
pub fn with_storage(storage: S) -> Self
Construct a new Db object with the given initial storage.
Sourcepub fn storage_mut(&mut self) -> &mut S
pub fn storage_mut(&mut self) -> &mut S
Retrieve a mutable reference to this Db’s storage.
Note that any mutations made to the storage using this are not tracked by the Db!
Using this incorrectly may break correctness!
Source§impl<S: Storage> Db<S>
impl<S: Storage> Db<S>
Sourcepub fn update_input<C>(&mut self, input: C, new_value: C::Output)where
C: Computation,
S: StorageFor<C>,
pub fn update_input<C>(&mut self, input: C, new_value: C::Output)where
C: Computation,
S: StorageFor<C>,
Updates an input with a new value
This requires an exclusive reference to self to ensure that there are no currently running queries. Updating an input while an incremental computation is occurring can break soundness for dependency tracking.
Panics if the given computation is not an input - ie. panics if it has at least 1 dependency.
Sourcepub fn is_stale<C: Computation>(&self, input: &C) -> boolwhere
S: StorageFor<C>,
pub fn is_stale<C: Computation>(&self, input: &C) -> boolwhere
S: StorageFor<C>,
True if a given computation is stale and needs to be re-computed. Computations which have never been computed are also considered stale.
Note that this may re-compute dependencies of the given computation.
Sourcepub fn get<C: Computation>(&self, compute: C) -> C::Outputwhere
S: StorageFor<C>,
pub fn get<C: Computation>(&self, compute: C) -> C::Outputwhere
S: StorageFor<C>,
Retrieves the up to date value for the given computation, re-running any dependencies as necessary.
This function can panic if the dynamic type of the value returned by compute.run(..) is not T.
Locking behavior: This function locks the cell corresponding to the given computation. This can cause a deadlock if the computation recursively depends on itself.
Sourcepub fn get_accumulated<Container, Item, C>(&self, compute: C) -> Container
pub fn get_accumulated<Container, Item, C>(&self, compute: C) -> Container
Retrieve an accumulated value in a container of the user’s choice. This will return all the accumulated items after the given computation.
Note that although this method will not re-perform the given computation, it will re-collect all the required accumulated items each time it is called, which may be costly for large dependency trees.
This is most often used for operations like retrieving diagnostics or logs.