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

True if a given input is stale and needs to be re-computed. Inputs which have never been computed are also considered stale.

This does not actually re-compute the input.

Source

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

Updates an input with a new value

Panics in debug mode if the input is not an input - ie. it has at least 1 dependency. Note that this check is skipped when compiling in Release mode.

Source

pub fn get<C: OutputType + ComputationId>(&mut 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.

Trait Implementations§

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>
where Storage: Freeze,

§

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

§

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>
where Storage: UnwindSafe,

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>,