Struct Collection

Source
pub struct Collection<In, Ix> { /* private fields */ }

Implementations§

Source§

impl<'t, In, Ix> Collection<In, Ix>
where Ix: Index<'t, In>,

Source

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}
Source

pub fn get(&self, key: Key) -> Option<&In>

Source

pub fn iter(&self) -> impl Iterator<Item = (&Key, &In)>

Source

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}
Source

pub fn update<F>(&mut self, key: Key, f: F)
where F: FnOnce(Option<&In>) -> In,

Source

pub fn delete(&mut self, key: Key)

Source

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}
Source

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>

§

impl<In, Ix> Send for Collection<In, Ix>
where Ix: Send, In: Send,

§

impl<In, Ix> Sync for Collection<In, Ix>
where Ix: Sync, In: Sync,

§

impl<In, Ix> Unpin for Collection<In, Ix>
where Ix: Unpin, In: Unpin,

§

impl<In, Ix> UnwindSafe for Collection<In, Ix>
where Ix: UnwindSafe, In: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.