pub struct Collection<In, Ix> { /* private fields */ }Implementations§
Source§impl<'t, In, Ix> Collection<In, Ix>where
Ix: Index<'t, In>,
impl<'t, In, Ix> Collection<In, Ix>where
Ix: Index<'t, In>,
Sourcepub fn new(ix: Ix) -> Self
pub fn new(ix: Ix) -> Self
Examples found in repository?
examples/simple.rs (lines 4-11)
3fn main() {
4 let mut db = Collection::<Person, _>::new(indexes::zip3(
5 // A hashtable index is useful for fast lookups
6 indexes::premap(|p: &Person| p.name.clone(), indexes::hashtable()),
7 // A btree index can provide max/min queries
8 indexes::premap(|p: &Person| p.birth_year, indexes::btree()),
9 // A grouped index can provide a "filtering" view
10 indexes::grouped(|p: &Person| p.starsign.clone(), || aggregations::count()),
11 ));
12
13 db.insert(Person::new("Alice".to_string(), 1990, StarSign::Aries));
14 db.insert(Person::new("Bob".to_string(), 1992, StarSign::Taurus));
15 db.insert(Person::new("Charlie".to_string(), 1991, StarSign::Aries));
16 db.insert(Person::new("Dave".to_string(), 1993, StarSign::Gemini));
17 let eve = Person::new("Eve".to_string(), 1984, StarSign::Cancer);
18 db.insert(eve.clone());
19 db.insert(Person::new("Frank".to_string(), 1995, StarSign::Gemini));
20 db.insert(Person::new("Grace".to_string(), 1996, StarSign::Cancer));
21 db.insert(Person::new("Heidi".to_string(), 1997, StarSign::Aries));
22
23 let q = db.query();
24
25 // Find a person by name, using the first index
26 let found = q.0.get_one(&"Eve".to_string());
27 assert_eq!(found, Some(&eve));
28
29 // Find the youngest person, using the second index
30 let youngest = q.1.max_one();
31 assert_eq!(
32 youngest,
33 Some((
34 &1997,
35 &Person::new("Heidi".to_string(), 1997, StarSign::Aries)
36 ))
37 );
38
39 // Count the number of Gemini for each star sign, using the third index
40 let gemini_count = q.2.get(&StarSign::Gemini);
41 assert_eq!(gemini_count, 2);
42}pub fn get(&self, key: Key) -> Option<&In>
pub fn iter(&self) -> impl Iterator<Item = (&Key, &In)>
Sourcepub fn insert(&mut self, value: In) -> Key
pub fn insert(&mut self, value: In) -> Key
Examples found in repository?
examples/simple.rs (line 13)
3fn main() {
4 let mut db = Collection::<Person, _>::new(indexes::zip3(
5 // A hashtable index is useful for fast lookups
6 indexes::premap(|p: &Person| p.name.clone(), indexes::hashtable()),
7 // A btree index can provide max/min queries
8 indexes::premap(|p: &Person| p.birth_year, indexes::btree()),
9 // A grouped index can provide a "filtering" view
10 indexes::grouped(|p: &Person| p.starsign.clone(), || aggregations::count()),
11 ));
12
13 db.insert(Person::new("Alice".to_string(), 1990, StarSign::Aries));
14 db.insert(Person::new("Bob".to_string(), 1992, StarSign::Taurus));
15 db.insert(Person::new("Charlie".to_string(), 1991, StarSign::Aries));
16 db.insert(Person::new("Dave".to_string(), 1993, StarSign::Gemini));
17 let eve = Person::new("Eve".to_string(), 1984, StarSign::Cancer);
18 db.insert(eve.clone());
19 db.insert(Person::new("Frank".to_string(), 1995, StarSign::Gemini));
20 db.insert(Person::new("Grace".to_string(), 1996, StarSign::Cancer));
21 db.insert(Person::new("Heidi".to_string(), 1997, StarSign::Aries));
22
23 let q = db.query();
24
25 // Find a person by name, using the first index
26 let found = q.0.get_one(&"Eve".to_string());
27 assert_eq!(found, Some(&eve));
28
29 // Find the youngest person, using the second index
30 let youngest = q.1.max_one();
31 assert_eq!(
32 youngest,
33 Some((
34 &1997,
35 &Person::new("Heidi".to_string(), 1997, StarSign::Aries)
36 ))
37 );
38
39 // Count the number of Gemini for each star sign, using the third index
40 let gemini_count = q.2.get(&StarSign::Gemini);
41 assert_eq!(gemini_count, 2);
42}pub fn update<F>(&mut self, key: Key, f: F)
pub fn delete(&mut self, key: Key)
Sourcepub fn query(&'t self) -> Ix::Query<In>
pub fn query(&'t self) -> Ix::Query<In>
Examples found in repository?
examples/simple.rs (line 23)
3fn main() {
4 let mut db = Collection::<Person, _>::new(indexes::zip3(
5 // A hashtable index is useful for fast lookups
6 indexes::premap(|p: &Person| p.name.clone(), indexes::hashtable()),
7 // A btree index can provide max/min queries
8 indexes::premap(|p: &Person| p.birth_year, indexes::btree()),
9 // A grouped index can provide a "filtering" view
10 indexes::grouped(|p: &Person| p.starsign.clone(), || aggregations::count()),
11 ));
12
13 db.insert(Person::new("Alice".to_string(), 1990, StarSign::Aries));
14 db.insert(Person::new("Bob".to_string(), 1992, StarSign::Taurus));
15 db.insert(Person::new("Charlie".to_string(), 1991, StarSign::Aries));
16 db.insert(Person::new("Dave".to_string(), 1993, StarSign::Gemini));
17 let eve = Person::new("Eve".to_string(), 1984, StarSign::Cancer);
18 db.insert(eve.clone());
19 db.insert(Person::new("Frank".to_string(), 1995, StarSign::Gemini));
20 db.insert(Person::new("Grace".to_string(), 1996, StarSign::Cancer));
21 db.insert(Person::new("Heidi".to_string(), 1997, StarSign::Aries));
22
23 let q = db.query();
24
25 // Find a person by name, using the first index
26 let found = q.0.get_one(&"Eve".to_string());
27 assert_eq!(found, Some(&eve));
28
29 // Find the youngest person, using the second index
30 let youngest = q.1.max_one();
31 assert_eq!(
32 youngest,
33 Some((
34 &1997,
35 &Person::new("Heidi".to_string(), 1997, StarSign::Aries)
36 ))
37 );
38
39 // Count the number of Gemini for each star sign, using the third index
40 let gemini_count = q.2.get(&StarSign::Gemini);
41 assert_eq!(gemini_count, 2);
42}pub fn len(&self) -> usize
Auto Trait Implementations§
impl<In, Ix> Freeze for Collection<In, Ix>where
Ix: Freeze,
impl<In, Ix> RefUnwindSafe for Collection<In, Ix>where
Ix: RefUnwindSafe,
In: RefUnwindSafe,
impl<In, Ix> Send for Collection<In, Ix>
impl<In, Ix> Sync for Collection<In, Ix>
impl<In, Ix> Unpin for Collection<In, Ix>
impl<In, Ix> UnwindSafe for Collection<In, Ix>where
Ix: UnwindSafe,
In: UnwindSafe,
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