pub struct Database { /* private fields */ }Implementations§
Source§impl Database
impl Database
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/database.rs (line 17)
14fn main() {
15 // Construct an empty database
16 // and add some facts about the world.
17 let mut db = Database::new();
18 db_facts! {
19 db {
20 food("Beef");
21 food("Fish");
22 food("Hamburger");
23 food("Pizza");
24 food("Salad");
25 food("Stone soup");
26 food("Veggies");
27
28 drink("Beer");
29 drink("Red wine");
30 drink("Water");
31 drink("White wine");
32
33 goes_well_with("Beef", "Beer");
34 goes_well_with("Beef", "Red wine");
35 goes_well_with("Fish", "White wine");
36 goes_well_with("Hamburger", "Beer");
37 goes_well_with("Pizza", "Red wine");
38 goes_well_with("Stone soup", "Water");
39 goes_well_with("Veggies", "White wine");
40
41 is_vegetarian("Beef", false);
42 is_vegetarian("Fish", "some say so");
43 is_vegetarian("Hamburger", "canbe");
44 is_vegetarian("Pizza", "canbe");
45 is_vegetarian("Salad", true);
46 is_vegetarian("Stone soup", true);
47 is_vegetarian("Veggies", true);
48 }
49 }
50
51 // Share database
52 let db = Arc::new(db);
53
54 // run a simple query
55 let food_: Vec<_> = run!(q, food(&db, q)).collect();
56 println!("All the food we like: {:?}", food_);
57
58 // run another simple query
59 let veggie: Vec<_> = run!(q, is_vegetarian(&db, q, true)).collect();
60 println!("Vegetarian food: {:?}", veggie);
61
62 // run a combined query
63 let wine_and_veggie: Vec<_> = run!(
64 q,
65 is_vegetarian(&db, q, true),
66 goes_well_with(&db, q, "White wine"),
67 )
68 .collect();
69 println!(
70 "Vegetarian food that goes well with white wine: {:?}",
71 wine_and_veggie
72 );
73
74 // run a query with alternatives
75 let any_wine: Vec<_> = run!(
76 q,
77 disj! {
78 goes_well_with(&db, q, "Red wine");
79 goes_well_with(&db, q, "White wine")
80 }
81 )
82 .collect();
83 println!("Food that goes well with wine: {:?}", any_wine);
84}pub fn insert(&mut self, table_name: &str, row: Vec<Value>)
pub fn query( &self, table_name: &str, ) -> impl Iterator<Item = impl Iterator<Item = &Value> + '_> + '_
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