pub struct View<T, E>where
T: Tuple,
E: Expression<T>,{ /* private fields */ }
Expand description
Represents a view in the database.
Example:
use codd::{Database, expression::{Product, View}};
let mut db = Database::new();
let dividends = db.add_relation("dividends").unwrap();
let divisors = db.add_relation("divisors").unwrap();
db.insert(÷nds, vec![6, 12, 18].into()).unwrap();
db.insert(&divisors, vec![2, 3].into()).unwrap();
// divide all elements of `dividends` by all elements of `divisors`:
let quotients = Product::new(
dividends.clone(),
divisors.clone(),
|&l, &r| l/r
);
let view = db.store_view(quotients.clone()).unwrap();
// `view` and `quotients` evaluate to the same result:
assert_eq!(vec![2, 3, 4, 6, 9], db.evaluate("ients).unwrap().into_tuples());
assert_eq!(vec![2, 3, 4, 6, 9], db.evaluate(&view).unwrap().into_tuples());
db.insert(÷nds, vec![24, 30].into());
db.insert(&divisors, vec![1].into());
// the view gets updated automatically:
assert_eq!(
vec![2, 3, 4, 6, 8, 9, 10, 12, 15, 18, 24, 30],
db.evaluate(&view).unwrap().into_tuples()
);
use codd::expression::Difference;
// incremental view update for `Difference` is currently not supported:
assert!(db.store_view(Difference::new(dividends, divisors)).is_err());
Trait Implementations§
Source§impl<T, E> Expression<T> for View<T, E>where
T: Tuple + 'static,
E: Expression<T> + 'static,
impl<T, E> Expression<T> for View<T, E>where
T: Tuple + 'static,
E: Expression<T> + 'static,
impl<T, E> Eq for View<T, E>
impl<T, E> StructuralPartialEq for View<T, E>where
T: Tuple,
E: Expression<T>,
Auto Trait Implementations§
impl<T, E> Freeze for View<T, E>
impl<T, E> RefUnwindSafe for View<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for View<T, E>
impl<T, E> Sync for View<T, E>
impl<T, E> Unpin for View<T, E>
impl<T, E> UnwindSafe for View<T, E>where
T: UnwindSafe,
E: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, E> IntoExpression<T, E> for Ewhere
T: Tuple,
E: Expression<T>,
impl<T, E> IntoExpression<T, E> for Ewhere
T: Tuple,
E: Expression<T>,
Source§fn into_expression(self) -> E
fn into_expression(self) -> E
Consumes the receiver and returns an expression.