Database

Struct Database 

Source
pub struct Database { /* private fields */ }
Expand description

The main type to interact with Yéter

This structure holds caches and effects for each query type.

Implementations§

Source§

impl Database

Source

pub fn new() -> Self

Creates an empty database

Examples found in repository?
examples/basic.rs (line 9)
8fn main() {
9    let db = yeter::Database::new();
10    let len1 = string::len(&db, "hello".into());
11    let len2 = string::len(&db, "hello".into());
12    let len3 = string::len(&db, "world".into());
13    assert_eq!(len1, len2);
14    assert_eq!(len1, len3);
15}
More examples
Hide additional examples
examples/effects.rs (line 12)
11fn main() {
12    let db = yeter::Database::new();
13    let len1 = string::len(&db, "".into());
14    for msg in db.effect::<&'static str>() {
15        println!("EFFECT [1]: {}", msg);
16    }
17    let len2 = string::len(&db, "".into());
18    for msg in db.effect::<&'static str>() {
19        println!("EFFECT [2]: {}", msg);
20    }
21    let len3 = string::len(&db, "aaaa".into());
22    for msg in db.effect::<&'static str>() {
23        println!("EFFECT [3]: {}", msg);
24    }
25    assert_eq!(len1, len2);
26    assert_eq!(*len3, 4);
27}
Source

pub fn run<'input, F, Q>(&self, f: F, i: Q::Input) -> Rc<Q::Output>
where F: Fn(&Database, Q::Input) -> Q::Output, Q: QueryDef, Q::Input: Hash + 'input, Q::Output: 'static,

Runs a query (or not if it the result is already in the cache)

Panics if a query ends up in a cyclic computation

Source

pub fn try_run<'input, F, Q>( &self, f: F, i: Q::Input, ) -> Result<Rc<Q::Output>, CycleError>
where F: Fn(&Database, Q::Input) -> Q::Output, Q: QueryDef, Q::Input: Hash + 'input, Q::Output: 'static,

Tries to runs a query (or not if it the result is already in the cache)

Source

pub fn effect<T: 'static + Clone + Send>(&self) -> Vec<T>

Returns a side effect collection

Examples found in repository?
examples/effects.rs (line 14)
11fn main() {
12    let db = yeter::Database::new();
13    let len1 = string::len(&db, "".into());
14    for msg in db.effect::<&'static str>() {
15        println!("EFFECT [1]: {}", msg);
16    }
17    let len2 = string::len(&db, "".into());
18    for msg in db.effect::<&'static str>() {
19        println!("EFFECT [2]: {}", msg);
20    }
21    let len3 = string::len(&db, "aaaa".into());
22    for msg in db.effect::<&'static str>() {
23        println!("EFFECT [3]: {}", msg);
24    }
25    assert_eq!(len1, len2);
26    assert_eq!(*len3, 4);
27}
Source

pub fn do_effect<T: 'static + Clone + Send>(&self, eff: T)

Produces a side effect

Examples found in repository?
examples/effects.rs (line 5)
3    pub fn len(db: &yeter::Database, input: String) -> usize {
4        if input.is_empty() {
5            db.do_effect("Empty string");
6        }
7        input.len()
8    }
Source

pub fn set<'input, Q>(&self, input: Q::Input, output: Q::Output)
where Q: InputQueryDef, Q::Input: Hash + 'input, Q::OptionalOutput: 'static,

Defines the a value

Trait Implementations§

Source§

impl Default for Database

Source§

fn default() -> Database

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

Auto Trait Implementations§

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> Any for T
where T: Any,