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
impl Database
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty database
Examples found in repository?
More 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}Sourcepub fn run<'input, F, Q>(&self, f: F, i: Q::Input) -> Rc<Q::Output>
pub fn run<'input, F, Q>(&self, f: F, i: Q::Input) -> Rc<Q::Output>
Runs a query (or not if it the result is already in the cache)
Panics if a query ends up in a cyclic computation
Sourcepub fn try_run<'input, F, Q>(
&self,
f: F,
i: Q::Input,
) -> Result<Rc<Q::Output>, CycleError>
pub fn try_run<'input, F, Q>( &self, f: F, i: Q::Input, ) -> Result<Rc<Q::Output>, CycleError>
Tries to runs a query (or not if it the result is already in the cache)
Sourcepub fn effect<T: 'static + Clone + Send>(&self) -> Vec<T>
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}Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Database
impl RefUnwindSafe for Database
impl !Send for Database
impl !Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more