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
impl Database
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty database
Examples found in repository?
More 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);
}sourcepub fn register<Q>(&mut self, f: fn(_: &Self, _: Q::Input) -> Q::Output)where
Q: QueryDef,
Q::Output: 'static + Sync,
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?
More 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);
}