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<Item, C>(&self, compute: C) -> BTreeSet<Item>
pub fn get_accumulated<Item, C>(&self, compute: C) -> BTreeSet<Item>
Retrieve each accumulated value of the given type after the given computation is run.
This is most often used for operations like retrieving diagnostics or logs.
Compared to Db::get_accumulated_uncached, this version reuses the normal flow for
queries and thus saves accumulated values for each intermediate query. This involves
more synching and data duplication but can be beneficial if intermediate results
ever need to be reused, e.g. if you call Db::get_accumulated in a loop where each
call may share dependencies. If you already have a single query which emits all the
accumulated values you need, Db::get_accumulated_uncached is likely faster, but
requires a &mut Db.
Sourcepub fn get_accumulated_uncached<Item, C>(
&mut self,
compute: C,
) -> BTreeSet<Item>where
S: StorageFor<C> + StorageFor<Accumulated<Item>> + Accumulate<Item>,
C: Computation,
Item: 'static + Ord,
pub fn get_accumulated_uncached<Item, C>(
&mut self,
compute: C,
) -> BTreeSet<Item>where
S: StorageFor<C> + StorageFor<Accumulated<Item>> + Accumulate<Item>,
C: Computation,
Item: 'static + Ord,
Retrieve each accumulated value of the given type after the given computation is run.
This is most often used for operations like retrieving diagnostics or logs.
This is a faster version of Db::get_accumulated for some use-cases. This version tends to be more efficient when you already have a single query which emits all the accumulated values you need, while the original Db::get_accumulated is more efficient when you have many smaller calls since it avoids duplicated work and is safe to call with only a DbHandle.