Struct yeter::Database

source ·
pub struct Database { /* private fields */ }
Expand description

The main type to interact with Yéter

This structure holds a list of registered queries and their respective caches.

Implementations§

source§

impl Database

source

pub fn new() -> Self

Creates an empty database

Examples found in repository?
examples/basic.rs (line 8)
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let mut db = yeter::Database::new();
    db.register::<string::len::Query>(|_db, name| {
        dbg!(name.len())
    });
    let len1 = string::len::query(&db, "hello".into());
    let len2 = string::len::query(&db, "hello".into());
    let len3 = string::len::query(&db, "world".into());
    assert_eq!(len1, len2);
    assert_eq!(len1, len3);
}
More examples
Hide additional examples
examples/invalidation.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut db = yeter::Database::new();
    db.register::<list::Query>(|_db, ()| {
        vec![1, 2, 3]
    });
    db.register::<sum::Query>(|db, ()| {
        list::query(db, ()).iter().sum()
    });
    assert_eq!(*sum::query(&db, ()), 6);

    db.register::<list::Query>(|_db, ()| {
        vec![]
    });
    assert_eq!(*sum::query(&db, ()), 0);
}
source

pub fn register<Q>(&mut self, f: fn(_: &Self, _: Q::Input) -> Q::Output)where
Q: QueryDef,
Q::Output: 'static + Sync,

Registers a query

Examples found in repository?
examples/basic.rs (lines 9-11)
7
8
9
10
11
12
13
14
15
16
17
fn main() {
    let mut db = yeter::Database::new();
    db.register::<string::len::Query>(|_db, name| {
        dbg!(name.len())
    });
    let len1 = string::len::query(&db, "hello".into());
    let len2 = string::len::query(&db, "hello".into());
    let len3 = string::len::query(&db, "world".into());
    assert_eq!(len1, len2);
    assert_eq!(len1, len3);
}
More examples
Hide additional examples
examples/invalidation.rs (lines 8-10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
fn main() {
    let mut db = yeter::Database::new();
    db.register::<list::Query>(|_db, ()| {
        vec![1, 2, 3]
    });
    db.register::<sum::Query>(|db, ()| {
        list::query(db, ()).iter().sum()
    });
    assert_eq!(*sum::query(&db, ()), 6);

    db.register::<list::Query>(|_db, ()| {
        vec![]
    });
    assert_eq!(*sum::query(&db, ()), 0);
}
source

pub fn run<I, O>(&self, q: &'static str, i: I) -> Rc<O>where
I: Hash,
O: 'static,

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

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 Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.