Skip to main content

project/
project.rs

1//! Demonstrates how to keep only selected attributes with the `PROJECT` operation.
2
3use darwen::prelude::{AttributeName, Relation, RelationBuilder, ScalarType};
4use darwen::{heading, tuple};
5
6fn hotline() -> Relation {
7    RelationBuilder::new()
8        .with_heading(
9            heading!(
10                name = ScalarType::String,
11                phone = ScalarType::String,
12                number = ScalarType::Integer
13            )
14            .unwrap(),
15        )
16        .with_body(vec![
17            tuple!(name = "Monica", phone = "212-85-06", number = 4).unwrap(),
18            tuple!(name = "Erica", phone = "212-85-06", number = 8).unwrap(),
19            tuple!(name = "Jessica", phone = "212-85-06", number = 42).unwrap(),
20        ])
21        .build()
22        .unwrap()
23}
24
25fn main() {
26    let hotline = hotline();
27
28    println!(
29        "{}",
30        hotline
31            .project(&[AttributeName::from("name"), AttributeName::from("number")])
32            .unwrap()
33    );
34}