Db

Struct Db 

Source
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<Storage: Default> Db<Storage>

Source

pub fn new() -> Self

Construct a new Db object using Default::default() for the initial storage.

Source§

impl<S> Db<S>

Source

pub fn with_storage(storage: S) -> Self

Construct a new Db object with the given initial storage.

Source

pub fn storage(&self) -> &S

Retrieve an immutable reference to this Db’s storage

Source

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>

Source

pub fn version(&self) -> u32

Source

pub fn gc(&mut self, version: u32)

Source§

impl<S: Storage> Db<S>

Source

pub fn update_input<C>(&mut self, input: C, new_value: C::Output)

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.

Source

pub fn is_stale<C: OutputType>(&self, input: &C) -> bool
where 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.

Source

pub fn get<C: OutputType + ComputationId>(&self, compute: C) -> C::Output
where 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.

Source

pub fn get_accumulated<Container, Item, C>(&self, compute: C) -> Container
where Container: FromIterator<Item>, S: Accumulate<Item> + StorageFor<C>, C: OutputType + ComputationId,

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.

Trait Implementations§

Source§

impl<S, C> DbGet<C> for Db<S>

Source§

fn get(&self, key: C) -> C::Output

Run an incremental computation C and return its output. If C is already cached, no computation will be performed.
Source§

impl<S: Default> Default for Db<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, Storage> Deserialize<'de> for Db<Storage>
where Storage: Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Storage> Serialize for Db<Storage>
where Storage: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Storage> !Freeze for Db<Storage>

§

impl<Storage> !RefUnwindSafe for Db<Storage>

§

impl<Storage> Send for Db<Storage>
where Storage: Send,

§

impl<Storage> Sync for Db<Storage>
where Storage: Sync,

§

impl<Storage> Unpin for Db<Storage>
where Storage: Unpin,

§

impl<Storage> !UnwindSafe for Db<Storage>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,