Builder

Struct Builder 

Source
pub struct Builder<L, Left>
where L: Tuple, Left: Expression<L>,
{ /* private fields */ }
Expand description

Is a builder for building Expression values.

Implementations§

Source§

impl<L, Left> Builder<L, Left>
where L: Tuple, Left: Expression<L>,

Source

pub fn project<T>( self, f: impl FnMut(&L) -> T + 'static, ) -> Builder<T, Project<L, T, Left>>
where T: Tuple,

Builds a Project expression over the receiver’s expression.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let fruit = db.add_relation::<String>("R").unwrap();

db.insert(&fruit, vec!["Apple".to_string(), "BANANA".into(), "cherry".into()].into());

let lower = fruit.builder().project(|t| t.to_lowercase()).build();

assert_eq!(vec!["apple", "banana", "cherry"], db.evaluate(&lower).unwrap().into_tuples());
Examples found in repository?
examples/music.rs (line 151)
34fn main() -> Result<(), Error> {
35    let mut music = Database::new();
36    let musician = music.add_relation("musician")?;
37    let band = music.add_relation("band")?;
38    let song = music.add_relation("song")?;
39    music.insert(
40        &musician,
41        vec![
42            Musician {
43                name: "John Petrucci".into(),
44                band: Some("Dream Theater".into()),
45                instruments: vec![Guitar],
46            },
47            Musician {
48                name: "Taylor Swift".into(),
49                band: None,
50                instruments: vec![Vocals],
51            },
52            Musician {
53                name: "Conor Mason".into(),
54                band: Some("Nothing But Thieves".into()),
55                instruments: vec![Vocals, Guitar],
56            },
57            Musician {
58                name: "Stevie Wonder".into(),
59                band: None,
60                instruments: vec![Vocals, Piano],
61            },
62            Musician {
63                name: "Jordan Rudess".into(),
64                band: Some("Dream Theater".into()),
65                instruments: vec![Keyboard],
66            },
67            Musician {
68                name: "Alex Turner".into(),
69                band: Some("Arctic Monkeys".into()),
70                instruments: vec![Vocals, Guitar, Piano],
71            },
72            Musician {
73                name: "Billie Eilish".into(),
74                band: None,
75                instruments: vec![Vocals, Piano],
76            },
77            Musician {
78                name: "Lars Ulrich".into(),
79                band: Some("Metallica".into()),
80                instruments: vec![Drums],
81            },
82        ]
83        .into(),
84    )?;
85
86    music.insert(
87        &band,
88        vec![
89            Band {
90                name: "Dream Theater".into(),
91                genre: "Progressive Metal".into(),
92            },
93            Band {
94                name: "Nothing But Thieves".into(),
95                genre: "Alternative Rock".into(),
96            },
97            Band {
98                name: "Metallica".into(),
99                genre: "Heavy Metal".into(),
100            },
101            Band {
102                name: "Arctic Monkeys".into(),
103                genre: "Indie Rock".into(),
104            },
105        ]
106        .into(),
107    )?;
108
109    music.insert(
110        &song,
111        vec![
112            Song {
113                title: "pull me under".into(),
114                artist: Either::Right("Dream Theater".into()),
115            },
116            Song {
117                title: "bad guy".into(),
118                artist: Either::Left("Billie Eilish".into()),
119            },
120            Song {
121                title: "excuse me".into(),
122                artist: Either::Left("Nothing But Thieves".into()),
123            },
124            Song {
125                title: "enter sandman".into(),
126                artist: Either::Right("Metallica".into()),
127            },
128            Song {
129                title: "panic attack".into(),
130                artist: Either::Right("Dream Theater".into()),
131            },
132            Song {
133                title: "shake it off".into(),
134                artist: Either::Left("Taylor Swift".into()),
135            },
136            Song {
137                title: "r u mine".into(),
138                artist: Either::Right("Artcic Monkeys".into()),
139            },
140            Song {
141                title: "as I am".into(),
142                artist: Either::Right("Dream Theater".into()),
143            },
144        ]
145        .into(),
146    )?;
147
148    let guitarist_name = musician
149        .builder()
150        .select(|m| m.instruments.contains(&Guitar))
151        .project(|g| g.name.to_string())
152        .build();
153
154    assert_eq!(
155        vec![
156            "Alex Turner".to_string(),
157            "Conor Mason".into(),
158            "John Petrucci".into(),
159        ],
160        music.evaluate(&guitarist_name)?.into_tuples()
161    );
162
163    let dt_member = musician
164        .builder()
165        .with_key(|m| m.band.clone())
166        .join(band.builder().with_key(|b| Some(b.name.clone())))
167        .on(|_, m, b| (m.name.to_string(), b.name.to_string()))
168        .select(|m| m.1 == "Dream Theater")
169        .project(|m| m.0.to_string())
170        .build();
171
172    assert_eq!(
173        vec!["John Petrucci".to_string(), "Jordan Rudess".into()],
174        music.evaluate(&dt_member)?.into_tuples()
175    );
176
177    let dt_member_view = music.store_view(dt_member)?;
178    let drummer_view = music.store_view(
179        musician
180            .builder()
181            .select(|m| m.instruments.contains(&Drums))
182            .build(),
183    )?;
184
185    music.insert(
186        &musician,
187        vec![
188            Musician {
189                name: "John Myung".into(),
190                band: Some("Dream Theater".into()),
191                instruments: vec![Guitar],
192            },
193            Musician {
194                name: "Mike Mangini".into(),
195                band: Some("Dream Theater".into()),
196                instruments: vec![Drums],
197            },
198        ]
199        .into(),
200    )?;
201
202    assert_eq!(
203        vec![
204            Musician {
205                name: "Lars Ulrich".into(),
206                band: Some("Metallica".into()),
207                instruments: vec![Drums]
208            },
209            Musician {
210                name: "Mike Mangini".into(),
211                band: Some("Dream Theater".into()),
212                instruments: vec![Drums]
213            }
214        ],
215        music.evaluate(&drummer_view)?.into_tuples()
216    );
217    assert_eq!(
218        vec![
219            "John Myung".to_string(),
220            "John Petrucci".into(),
221            "Jordan Rudess".into(),
222            "Mike Mangini".into()
223        ],
224        music.evaluate(&dt_member_view)?.into_tuples()
225    );
226
227    Ok(())
228}
Source

pub fn select( self, f: impl FnMut(&L) -> bool + 'static, ) -> Builder<L, Select<L, Left>>

Builds a Select expression over the receiver’s expression.


Example:

use codd::{Database, Expression};

let mut db = Database::new();
let fruit = db.add_relation::<String>("Fruit").unwrap();

db.insert(&fruit, vec!["Apple".to_string(), "BANANA".into(), "cherry".into()].into());

let select = fruit.builder().select(|t| t.contains('A')).build();

assert_eq!(vec!["Apple", "BANANA"], db.evaluate(&select).unwrap().into_tuples());
Examples found in repository?
examples/music.rs (line 150)
34fn main() -> Result<(), Error> {
35    let mut music = Database::new();
36    let musician = music.add_relation("musician")?;
37    let band = music.add_relation("band")?;
38    let song = music.add_relation("song")?;
39    music.insert(
40        &musician,
41        vec![
42            Musician {
43                name: "John Petrucci".into(),
44                band: Some("Dream Theater".into()),
45                instruments: vec![Guitar],
46            },
47            Musician {
48                name: "Taylor Swift".into(),
49                band: None,
50                instruments: vec![Vocals],
51            },
52            Musician {
53                name: "Conor Mason".into(),
54                band: Some("Nothing But Thieves".into()),
55                instruments: vec![Vocals, Guitar],
56            },
57            Musician {
58                name: "Stevie Wonder".into(),
59                band: None,
60                instruments: vec![Vocals, Piano],
61            },
62            Musician {
63                name: "Jordan Rudess".into(),
64                band: Some("Dream Theater".into()),
65                instruments: vec![Keyboard],
66            },
67            Musician {
68                name: "Alex Turner".into(),
69                band: Some("Arctic Monkeys".into()),
70                instruments: vec![Vocals, Guitar, Piano],
71            },
72            Musician {
73                name: "Billie Eilish".into(),
74                band: None,
75                instruments: vec![Vocals, Piano],
76            },
77            Musician {
78                name: "Lars Ulrich".into(),
79                band: Some("Metallica".into()),
80                instruments: vec![Drums],
81            },
82        ]
83        .into(),
84    )?;
85
86    music.insert(
87        &band,
88        vec![
89            Band {
90                name: "Dream Theater".into(),
91                genre: "Progressive Metal".into(),
92            },
93            Band {
94                name: "Nothing But Thieves".into(),
95                genre: "Alternative Rock".into(),
96            },
97            Band {
98                name: "Metallica".into(),
99                genre: "Heavy Metal".into(),
100            },
101            Band {
102                name: "Arctic Monkeys".into(),
103                genre: "Indie Rock".into(),
104            },
105        ]
106        .into(),
107    )?;
108
109    music.insert(
110        &song,
111        vec![
112            Song {
113                title: "pull me under".into(),
114                artist: Either::Right("Dream Theater".into()),
115            },
116            Song {
117                title: "bad guy".into(),
118                artist: Either::Left("Billie Eilish".into()),
119            },
120            Song {
121                title: "excuse me".into(),
122                artist: Either::Left("Nothing But Thieves".into()),
123            },
124            Song {
125                title: "enter sandman".into(),
126                artist: Either::Right("Metallica".into()),
127            },
128            Song {
129                title: "panic attack".into(),
130                artist: Either::Right("Dream Theater".into()),
131            },
132            Song {
133                title: "shake it off".into(),
134                artist: Either::Left("Taylor Swift".into()),
135            },
136            Song {
137                title: "r u mine".into(),
138                artist: Either::Right("Artcic Monkeys".into()),
139            },
140            Song {
141                title: "as I am".into(),
142                artist: Either::Right("Dream Theater".into()),
143            },
144        ]
145        .into(),
146    )?;
147
148    let guitarist_name = musician
149        .builder()
150        .select(|m| m.instruments.contains(&Guitar))
151        .project(|g| g.name.to_string())
152        .build();
153
154    assert_eq!(
155        vec![
156            "Alex Turner".to_string(),
157            "Conor Mason".into(),
158            "John Petrucci".into(),
159        ],
160        music.evaluate(&guitarist_name)?.into_tuples()
161    );
162
163    let dt_member = musician
164        .builder()
165        .with_key(|m| m.band.clone())
166        .join(band.builder().with_key(|b| Some(b.name.clone())))
167        .on(|_, m, b| (m.name.to_string(), b.name.to_string()))
168        .select(|m| m.1 == "Dream Theater")
169        .project(|m| m.0.to_string())
170        .build();
171
172    assert_eq!(
173        vec!["John Petrucci".to_string(), "Jordan Rudess".into()],
174        music.evaluate(&dt_member)?.into_tuples()
175    );
176
177    let dt_member_view = music.store_view(dt_member)?;
178    let drummer_view = music.store_view(
179        musician
180            .builder()
181            .select(|m| m.instruments.contains(&Drums))
182            .build(),
183    )?;
184
185    music.insert(
186        &musician,
187        vec![
188            Musician {
189                name: "John Myung".into(),
190                band: Some("Dream Theater".into()),
191                instruments: vec![Guitar],
192            },
193            Musician {
194                name: "Mike Mangini".into(),
195                band: Some("Dream Theater".into()),
196                instruments: vec![Drums],
197            },
198        ]
199        .into(),
200    )?;
201
202    assert_eq!(
203        vec![
204            Musician {
205                name: "Lars Ulrich".into(),
206                band: Some("Metallica".into()),
207                instruments: vec![Drums]
208            },
209            Musician {
210                name: "Mike Mangini".into(),
211                band: Some("Dream Theater".into()),
212                instruments: vec![Drums]
213            }
214        ],
215        music.evaluate(&drummer_view)?.into_tuples()
216    );
217    assert_eq!(
218        vec![
219            "John Myung".to_string(),
220            "John Petrucci".into(),
221            "Jordan Rudess".into(),
222            "Mike Mangini".into()
223        ],
224        music.evaluate(&dt_member_view)?.into_tuples()
225    );
226
227    Ok(())
228}
Source

pub fn intersect<Right, I>( self, other: I, ) -> Builder<L, Intersect<L, Left, Right>>
where Right: Expression<L>, I: IntoExpression<L, Right>,

Builds an Intersect expression with the receiver’s expression on left and other on right.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let r = db.add_relation::<i32>("R").unwrap();
let s = db.add_relation::<i32>("S").unwrap();

db.insert(&r, vec![0, 1, 2].into());
db.insert(&s, vec![2, 4].into());

let intersect = r.builder().intersect(s).build();

assert_eq!(vec![2], db.evaluate(&intersect).unwrap().into_tuples());
Source

pub fn difference<Right, I>( self, other: I, ) -> Builder<L, Difference<L, Left, Right>>
where Right: Expression<L>, I: IntoExpression<L, Right>,

Builds a Difference expression with the receiver’s expression on left and other on right.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let r = db.add_relation::<i32>("R").unwrap();
let s = db.add_relation::<i32>("S").unwrap();

db.insert(&r, vec![0, 1, 2].into());
db.insert(&s, vec![2, 4].into());

let r_s = r.builder().difference(&s).build();
let s_r = s.builder().difference(r).build();

assert_eq!(vec![0, 1], db.evaluate(&r_s).unwrap().into_tuples());
assert_eq!(vec![4], db.evaluate(&s_r).unwrap().into_tuples());
Source

pub fn union<Right, I>(self, other: I) -> Builder<L, Union<L, Left, Right>>
where Right: Expression<L>, I: IntoExpression<L, Right>,

Builds a Union expression with the receiver’s expression on left and other on right.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let r = db.add_relation::<i32>("R").unwrap();
let s = db.add_relation::<i32>("S").unwrap();

db.insert(&r, vec![0, 1, 2].into());
db.insert(&s, vec![2, 4].into());

let union = r.builder().union(s).build();

assert_eq!(vec![0, 1, 2, 4], db.evaluate(&union).unwrap().into_tuples());
Source

pub fn product<R, Right, I>(self, other: I) -> ProductBuilder<L, R, Left, Right>
where R: Tuple, Right: Expression<R>, I: IntoExpression<R, Right>,

Combines the receiver’s expression with other in a temporary builder, which then can be turned into a Product expression using a combining closure provided by method on.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let r = db.add_relation::<i32>("R").unwrap();
let s = db.add_relation::<i32>("S").unwrap();

db.insert(&r, vec![0, 1, 2].into());
db.insert(&s, vec![2, 4].into());

let prod = r.builder().product(s).on(|l, r| l*r).build();

assert_eq!(vec![0, 2, 4, 8], db.evaluate(&prod).unwrap().into_tuples());
Source

pub fn with_key<K>( self, f: impl FnMut(&L) -> K + 'static, ) -> WithKeyBuilder<K, L, Left>
where K: Tuple,

Combines the receiver’s expression with closure f as the join key. This value can then be joined with another expression and it’s key to create a temporary join builder. Finally, the temporary builder can be turned into a Join expression using a combining closure provided by method on.

Example:

use codd::{Database, Expression};

let mut db = Database::new();
let fruit = db.add_relation::<(i32, String)>("R").unwrap();
let numbers = db.add_relation::<i32>("S").unwrap();

db.insert(&fruit, vec![
   (0, "Apple".to_string()),
   (1, "Banana".into()),
   (2, "Cherry".into())
].into());
db.insert(&numbers, vec![0, 2].into());

let join = fruit
    .builder()
    .with_key(|t| t.0) // first element of tuples in `r` is the key for join
    .join(numbers.builder().with_key(|&t| t))
    .on(|k, l, r| format!("{}{}", l.1, k + r))
        // combine the key `k`, left tuple `l` and right tuple `r`:    
    .build();
     
assert_eq!(vec!["Apple0", "Cherry4"], db.evaluate(&join).unwrap().into_tuples());
Examples found in repository?
examples/music.rs (line 165)
34fn main() -> Result<(), Error> {
35    let mut music = Database::new();
36    let musician = music.add_relation("musician")?;
37    let band = music.add_relation("band")?;
38    let song = music.add_relation("song")?;
39    music.insert(
40        &musician,
41        vec![
42            Musician {
43                name: "John Petrucci".into(),
44                band: Some("Dream Theater".into()),
45                instruments: vec![Guitar],
46            },
47            Musician {
48                name: "Taylor Swift".into(),
49                band: None,
50                instruments: vec![Vocals],
51            },
52            Musician {
53                name: "Conor Mason".into(),
54                band: Some("Nothing But Thieves".into()),
55                instruments: vec![Vocals, Guitar],
56            },
57            Musician {
58                name: "Stevie Wonder".into(),
59                band: None,
60                instruments: vec![Vocals, Piano],
61            },
62            Musician {
63                name: "Jordan Rudess".into(),
64                band: Some("Dream Theater".into()),
65                instruments: vec![Keyboard],
66            },
67            Musician {
68                name: "Alex Turner".into(),
69                band: Some("Arctic Monkeys".into()),
70                instruments: vec![Vocals, Guitar, Piano],
71            },
72            Musician {
73                name: "Billie Eilish".into(),
74                band: None,
75                instruments: vec![Vocals, Piano],
76            },
77            Musician {
78                name: "Lars Ulrich".into(),
79                band: Some("Metallica".into()),
80                instruments: vec![Drums],
81            },
82        ]
83        .into(),
84    )?;
85
86    music.insert(
87        &band,
88        vec![
89            Band {
90                name: "Dream Theater".into(),
91                genre: "Progressive Metal".into(),
92            },
93            Band {
94                name: "Nothing But Thieves".into(),
95                genre: "Alternative Rock".into(),
96            },
97            Band {
98                name: "Metallica".into(),
99                genre: "Heavy Metal".into(),
100            },
101            Band {
102                name: "Arctic Monkeys".into(),
103                genre: "Indie Rock".into(),
104            },
105        ]
106        .into(),
107    )?;
108
109    music.insert(
110        &song,
111        vec![
112            Song {
113                title: "pull me under".into(),
114                artist: Either::Right("Dream Theater".into()),
115            },
116            Song {
117                title: "bad guy".into(),
118                artist: Either::Left("Billie Eilish".into()),
119            },
120            Song {
121                title: "excuse me".into(),
122                artist: Either::Left("Nothing But Thieves".into()),
123            },
124            Song {
125                title: "enter sandman".into(),
126                artist: Either::Right("Metallica".into()),
127            },
128            Song {
129                title: "panic attack".into(),
130                artist: Either::Right("Dream Theater".into()),
131            },
132            Song {
133                title: "shake it off".into(),
134                artist: Either::Left("Taylor Swift".into()),
135            },
136            Song {
137                title: "r u mine".into(),
138                artist: Either::Right("Artcic Monkeys".into()),
139            },
140            Song {
141                title: "as I am".into(),
142                artist: Either::Right("Dream Theater".into()),
143            },
144        ]
145        .into(),
146    )?;
147
148    let guitarist_name = musician
149        .builder()
150        .select(|m| m.instruments.contains(&Guitar))
151        .project(|g| g.name.to_string())
152        .build();
153
154    assert_eq!(
155        vec![
156            "Alex Turner".to_string(),
157            "Conor Mason".into(),
158            "John Petrucci".into(),
159        ],
160        music.evaluate(&guitarist_name)?.into_tuples()
161    );
162
163    let dt_member = musician
164        .builder()
165        .with_key(|m| m.band.clone())
166        .join(band.builder().with_key(|b| Some(b.name.clone())))
167        .on(|_, m, b| (m.name.to_string(), b.name.to_string()))
168        .select(|m| m.1 == "Dream Theater")
169        .project(|m| m.0.to_string())
170        .build();
171
172    assert_eq!(
173        vec!["John Petrucci".to_string(), "Jordan Rudess".into()],
174        music.evaluate(&dt_member)?.into_tuples()
175    );
176
177    let dt_member_view = music.store_view(dt_member)?;
178    let drummer_view = music.store_view(
179        musician
180            .builder()
181            .select(|m| m.instruments.contains(&Drums))
182            .build(),
183    )?;
184
185    music.insert(
186        &musician,
187        vec![
188            Musician {
189                name: "John Myung".into(),
190                band: Some("Dream Theater".into()),
191                instruments: vec![Guitar],
192            },
193            Musician {
194                name: "Mike Mangini".into(),
195                band: Some("Dream Theater".into()),
196                instruments: vec![Drums],
197            },
198        ]
199        .into(),
200    )?;
201
202    assert_eq!(
203        vec![
204            Musician {
205                name: "Lars Ulrich".into(),
206                band: Some("Metallica".into()),
207                instruments: vec![Drums]
208            },
209            Musician {
210                name: "Mike Mangini".into(),
211                band: Some("Dream Theater".into()),
212                instruments: vec![Drums]
213            }
214        ],
215        music.evaluate(&drummer_view)?.into_tuples()
216    );
217    assert_eq!(
218        vec![
219            "John Myung".to_string(),
220            "John Petrucci".into(),
221            "Jordan Rudess".into(),
222            "Mike Mangini".into()
223        ],
224        music.evaluate(&dt_member_view)?.into_tuples()
225    );
226
227    Ok(())
228}
Source

pub fn build(self) -> Left

Builds an expression from the receiver.

Examples found in repository?
examples/music.rs (line 152)
34fn main() -> Result<(), Error> {
35    let mut music = Database::new();
36    let musician = music.add_relation("musician")?;
37    let band = music.add_relation("band")?;
38    let song = music.add_relation("song")?;
39    music.insert(
40        &musician,
41        vec![
42            Musician {
43                name: "John Petrucci".into(),
44                band: Some("Dream Theater".into()),
45                instruments: vec![Guitar],
46            },
47            Musician {
48                name: "Taylor Swift".into(),
49                band: None,
50                instruments: vec![Vocals],
51            },
52            Musician {
53                name: "Conor Mason".into(),
54                band: Some("Nothing But Thieves".into()),
55                instruments: vec![Vocals, Guitar],
56            },
57            Musician {
58                name: "Stevie Wonder".into(),
59                band: None,
60                instruments: vec![Vocals, Piano],
61            },
62            Musician {
63                name: "Jordan Rudess".into(),
64                band: Some("Dream Theater".into()),
65                instruments: vec![Keyboard],
66            },
67            Musician {
68                name: "Alex Turner".into(),
69                band: Some("Arctic Monkeys".into()),
70                instruments: vec![Vocals, Guitar, Piano],
71            },
72            Musician {
73                name: "Billie Eilish".into(),
74                band: None,
75                instruments: vec![Vocals, Piano],
76            },
77            Musician {
78                name: "Lars Ulrich".into(),
79                band: Some("Metallica".into()),
80                instruments: vec![Drums],
81            },
82        ]
83        .into(),
84    )?;
85
86    music.insert(
87        &band,
88        vec![
89            Band {
90                name: "Dream Theater".into(),
91                genre: "Progressive Metal".into(),
92            },
93            Band {
94                name: "Nothing But Thieves".into(),
95                genre: "Alternative Rock".into(),
96            },
97            Band {
98                name: "Metallica".into(),
99                genre: "Heavy Metal".into(),
100            },
101            Band {
102                name: "Arctic Monkeys".into(),
103                genre: "Indie Rock".into(),
104            },
105        ]
106        .into(),
107    )?;
108
109    music.insert(
110        &song,
111        vec![
112            Song {
113                title: "pull me under".into(),
114                artist: Either::Right("Dream Theater".into()),
115            },
116            Song {
117                title: "bad guy".into(),
118                artist: Either::Left("Billie Eilish".into()),
119            },
120            Song {
121                title: "excuse me".into(),
122                artist: Either::Left("Nothing But Thieves".into()),
123            },
124            Song {
125                title: "enter sandman".into(),
126                artist: Either::Right("Metallica".into()),
127            },
128            Song {
129                title: "panic attack".into(),
130                artist: Either::Right("Dream Theater".into()),
131            },
132            Song {
133                title: "shake it off".into(),
134                artist: Either::Left("Taylor Swift".into()),
135            },
136            Song {
137                title: "r u mine".into(),
138                artist: Either::Right("Artcic Monkeys".into()),
139            },
140            Song {
141                title: "as I am".into(),
142                artist: Either::Right("Dream Theater".into()),
143            },
144        ]
145        .into(),
146    )?;
147
148    let guitarist_name = musician
149        .builder()
150        .select(|m| m.instruments.contains(&Guitar))
151        .project(|g| g.name.to_string())
152        .build();
153
154    assert_eq!(
155        vec![
156            "Alex Turner".to_string(),
157            "Conor Mason".into(),
158            "John Petrucci".into(),
159        ],
160        music.evaluate(&guitarist_name)?.into_tuples()
161    );
162
163    let dt_member = musician
164        .builder()
165        .with_key(|m| m.band.clone())
166        .join(band.builder().with_key(|b| Some(b.name.clone())))
167        .on(|_, m, b| (m.name.to_string(), b.name.to_string()))
168        .select(|m| m.1 == "Dream Theater")
169        .project(|m| m.0.to_string())
170        .build();
171
172    assert_eq!(
173        vec!["John Petrucci".to_string(), "Jordan Rudess".into()],
174        music.evaluate(&dt_member)?.into_tuples()
175    );
176
177    let dt_member_view = music.store_view(dt_member)?;
178    let drummer_view = music.store_view(
179        musician
180            .builder()
181            .select(|m| m.instruments.contains(&Drums))
182            .build(),
183    )?;
184
185    music.insert(
186        &musician,
187        vec![
188            Musician {
189                name: "John Myung".into(),
190                band: Some("Dream Theater".into()),
191                instruments: vec![Guitar],
192            },
193            Musician {
194                name: "Mike Mangini".into(),
195                band: Some("Dream Theater".into()),
196                instruments: vec![Drums],
197            },
198        ]
199        .into(),
200    )?;
201
202    assert_eq!(
203        vec![
204            Musician {
205                name: "Lars Ulrich".into(),
206                band: Some("Metallica".into()),
207                instruments: vec![Drums]
208            },
209            Musician {
210                name: "Mike Mangini".into(),
211                band: Some("Dream Theater".into()),
212                instruments: vec![Drums]
213            }
214        ],
215        music.evaluate(&drummer_view)?.into_tuples()
216    );
217    assert_eq!(
218        vec![
219            "John Myung".to_string(),
220            "John Petrucci".into(),
221            "Jordan Rudess".into(),
222            "Mike Mangini".into()
223        ],
224        music.evaluate(&dt_member_view)?.into_tuples()
225    );
226
227    Ok(())
228}

Trait Implementations§

Source§

impl<T, E> From<E> for Builder<T, E>
where T: Tuple, E: Expression<T>,

Source§

fn from(expression: E) -> Self

Converts to this type from the input type.
Source§

impl<T, E> IntoExpression<T, E> for Builder<T, E>
where T: Tuple, E: Expression<T>,

Source§

fn into_expression(self) -> E

Consumes the receiver and returns an expression.

Auto Trait Implementations§

§

impl<L, Left> Freeze for Builder<L, Left>
where Left: Freeze,

§

impl<L, Left> RefUnwindSafe for Builder<L, Left>
where Left: RefUnwindSafe, L: RefUnwindSafe,

§

impl<L, Left> Send for Builder<L, Left>
where Left: Send, L: Send,

§

impl<L, Left> Sync for Builder<L, Left>
where Left: Sync, L: Sync,

§

impl<L, Left> Unpin for Builder<L, Left>
where Left: Unpin, L: Unpin,

§

impl<L, Left> UnwindSafe for Builder<L, Left>
where Left: UnwindSafe, L: 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.