Skip to main content

Join

Struct Join 

Source
pub struct Join<K, L, R, Left, Right, T>
where K: Tuple, L: Tuple, R: Tuple, T: Tuple, Left: Expression<L>, Right: Expression<R>,
{ /* private fields */ }
Expand description

Represents the join of its left and right sub-expressions.

Example:

use codd::{Database, expression::Join};

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".to_string()),
   (2, "Cherry".to_string())
].into());
db.insert(&numbers, vec![0, 2].into());

let join = Join::new(
    &fruit,
    &numbers,
    |t| t.0,  // first element of tuples in `r` is the key for join
    |&t| t,   // the values in `s` are keys for join
    // make resulting values from key `k`, left value `l` and right value `r`:
    |k, l, r| format!("{}{}", l.1, k + r)
);

assert_eq!(vec!["Apple0", "Cherry4"], db.evaluate(&join).unwrap().into_tuples());

Implementations§

Source§

impl<K, L, R, Left, Right, T> Join<K, L, R, Left, Right, T>
where K: Tuple, L: Tuple, R: Tuple, T: Tuple, Left: Expression<L>, Right: Expression<R>,

Source

pub fn new<IL, IR>( left: IL, right: IR, left_key: impl FnMut(&L) -> K + 'static, right_key: impl FnMut(&R) -> K + 'static, mapper: impl FnMut(&K, &L, &R) -> T + 'static, ) -> Self
where IL: IntoExpression<L, Left>, IR: IntoExpression<R, Right>,

Creates a new Join expression over left and right where left_key and right_key are closures that return the join key for tuples of left and right respectively. The closure mapper computes the tuples of the resulting expression from the join key and the tuples of left and right.

Source

pub fn left(&self) -> &Left

Returns a reference to the left sub-expression.

Source

pub fn right(&self) -> &Right

Returns a reference to the right sub-expression.

Trait Implementations§

Source§

impl<K, L, R, Left, Right, T> Clone for Join<K, L, R, Left, Right, T>
where K: Tuple + Clone, L: Tuple + Clone, R: Tuple + Clone, T: Tuple + Clone, Left: Expression<L> + Clone, Right: Expression<R> + Clone,

Source§

fn clone(&self) -> Join<K, L, R, Left, Right, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, L, R, Left, Right, T> Debug for Join<K, L, R, Left, Right, T>
where K: Tuple, L: Tuple, R: Tuple, T: Tuple, Left: Expression<L>, Right: Expression<R>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, L, R, Left, Right, T> Expression<T> for Join<K, L, R, Left, Right, T>
where K: Tuple, L: Tuple, R: Tuple, T: Tuple, Left: Expression<L>, Right: Expression<R>,

Source§

fn visit<V>(&self, visitor: &mut V)
where V: Visitor,

Visits this expression by a Visitor.
Source§

fn builder(&self) -> Builder<T, Self>

Returns an expression builder over this expression.
Source§

impl<T: Tuple> From<Join<T, T, T, Mono<T>, Mono<T>, T>> for Mono<T>

Source§

fn from(join: Join<T, T, T, Mono<T>, Mono<T>, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<K, L, R, Left, Right, T> Freeze for Join<K, L, R, Left, Right, T>
where Left: Freeze, Right: Freeze,

§

impl<K, L, R, Left, Right, T> !RefUnwindSafe for Join<K, L, R, Left, Right, T>

§

impl<K, L, R, Left, Right, T> !Send for Join<K, L, R, Left, Right, T>

§

impl<K, L, R, Left, Right, T> !Sync for Join<K, L, R, Left, Right, T>

§

impl<K, L, R, Left, Right, T> Unpin for Join<K, L, R, Left, Right, T>
where Left: Unpin, Right: Unpin,

§

impl<K, L, R, Left, Right, T> UnsafeUnpin for Join<K, L, R, Left, Right, T>
where Left: UnsafeUnpin, Right: UnsafeUnpin,

§

impl<K, L, R, Left, Right, T> !UnwindSafe for Join<K, L, R, Left, Right, T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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, E> IntoExpression<T, E> for E
where T: Tuple, E: Expression<T>,

Source§

fn into_expression(self) -> E

Consumes the receiver and returns an expression.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.