Skip to main content

divide/
divide.rs

1//! Demonstrates how to find tuples related to all tuples of another relation with the `DIVIDE` operation.
2
3use darwen::{
4    heading,
5    prelude::{Relation, RelationBuilder, ScalarType},
6    tuple,
7};
8
9fn enrollments() -> Relation {
10    RelationBuilder::new()
11        .with_heading(heading!(student = ScalarType::String, course = ScalarType::String).unwrap())
12        .with_body(vec![
13            tuple!(student = "Ann", course = "Math").unwrap(),
14            tuple!(student = "Ann", course = "Rust").unwrap(),
15            tuple!(student = "Bob", course = "Math").unwrap(),
16            tuple!(student = "Bob", course = "Rust").unwrap(),
17            tuple!(student = "Bob", course = "DB").unwrap(),
18            tuple!(student = "Kate", course = "Math").unwrap(),
19        ])
20        .build()
21        .unwrap()
22}
23
24fn required_courses() -> Relation {
25    RelationBuilder::new()
26        .with_heading(heading!(course = ScalarType::String).unwrap())
27        .with_body(vec![
28            tuple!(course = "Math").unwrap(),
29            tuple!(course = "Rust").unwrap(),
30        ])
31        .build()
32        .unwrap()
33}
34
35fn main() {
36    let enrollments = enrollments();
37    let required_courses = required_courses();
38
39    println!("{}", enrollments.divide(&required_courses).unwrap());
40}