LazyJoinQuery

Struct LazyJoinQuery 

Source
pub struct LazyJoinQuery<'a, L: 'static, R: 'static> { /* private fields */ }
Expand description

A lazy join query builder that returns iterators instead of collecting results.

Supports inner joins and left joins with deferred execution for better performance on large datasets.

§Type Parameters

  • 'a - The lifetime of the data being joined
  • L - The type of items in the left collection
  • R - The type of items in the right collection

§Example

let user_orders = LazyJoinQuery::new(&users, &orders)
    .inner_join_lazy(
        User::id(),
        Order::user_id(),
        |user, order| (user.name.clone(), order.total)
    );

// Nothing executed yet - just an iterator
let first_5: Vec<_> = user_orders.take(5).collect();

Implementations§

Source§

impl<'a, L: 'static, R: 'static> LazyJoinQuery<'a, L, R>

Source

pub fn new(left: &'a [L], right: &'a [R]) -> Self

Creates a new lazy join query from two collections.

§Arguments
  • left - The left collection to join
  • right - The right collection to join
§Example
let join = LazyJoinQuery::new(&users, &orders);
Source

pub fn inner_join_lazy<K, O, F>( &self, left_key: KeyPaths<L, K>, right_key: KeyPaths<R, K>, mapper: F, ) -> impl Iterator<Item = O> + 'a
where K: Eq + Hash + Clone + 'static, F: Fn(&'a L, &'a R) -> O + 'a, O: 'a,

Performs a lazy inner join between two collections.

Returns an iterator over matching pairs. The join is evaluated lazily, allowing for early termination and memory efficiency.

§Arguments
  • left_key - Key-path to the join field in the left collection
  • right_key - Key-path to the join field in the right collection
  • mapper - Function to transform matching pairs into the result type
§Example
let results: Vec<_> = LazyJoinQuery::new(&users, &orders)
    .inner_join_lazy(
        User::id(),
        Order::user_id(),
        |user, order| (user.name.clone(), order.total)
    )
    .take(10)  // Early termination - only process first 10 matches
    .collect();
Source

pub fn left_join_lazy<K, O, F>( &self, left_key: KeyPaths<L, K>, right_key: KeyPaths<R, K>, mapper: F, ) -> impl Iterator<Item = O> + 'a
where K: Eq + Hash + Clone + 'static, F: Fn(&'a L, Option<&'a R>) -> O + 'a, O: 'a,

Performs a lazy left join between two collections.

Returns an iterator over all left items with optional right matches. The join is evaluated lazily, allowing for early termination.

§Arguments
  • left_key - Key-path to the join field in the left collection
  • right_key - Key-path to the join field in the right collection
  • mapper - Function to transform pairs into the result type (right item may be None)
§Example
let results: Vec<_> = LazyJoinQuery::new(&users, &orders)
    .left_join_lazy(
        User::id(),
        Order::user_id(),
        |user, order| match order {
            Some(o) => format!("{} has order {}", user.name, o.id),
            None => format!("{} has no orders", user.name),
        }
    )
    .take(5)  // Early termination
    .collect();
Source

pub fn inner_join_where_lazy<K, O, F, P>( &self, left_key: KeyPaths<L, K>, right_key: KeyPaths<R, K>, predicate: P, mapper: F, ) -> impl Iterator<Item = O> + 'a
where K: Eq + Hash + Clone + 'static, F: Fn(&'a L, &'a R) -> O + 'a, P: Fn(&'a L, &'a R) -> bool + 'a, O: 'a,

Performs a lazy inner join with an additional filter predicate.

Like inner_join_lazy, but only includes pairs that satisfy both the join condition and the additional predicate.

§Arguments
  • left_key - Key-path to the join field in the left collection
  • right_key - Key-path to the join field in the right collection
  • predicate - Additional condition that must be true for pairs to be included
  • mapper - Function to transform matching pairs into the result type
§Example
let results: Vec<_> = LazyJoinQuery::new(&orders, &products)
    .inner_join_where_lazy(
        Order::product_id(),
        Product::id(),
        |order, _product| order.total > 100.0,
        |order, product| (product.name.clone(), order.total)
    )
    .take(10)
    .collect();

Auto Trait Implementations§

§

impl<'a, L, R> Freeze for LazyJoinQuery<'a, L, R>

§

impl<'a, L, R> RefUnwindSafe for LazyJoinQuery<'a, L, R>

§

impl<'a, L, R> Send for LazyJoinQuery<'a, L, R>
where L: Sync, R: Sync,

§

impl<'a, L, R> Sync for LazyJoinQuery<'a, L, R>
where L: Sync, R: Sync,

§

impl<'a, L, R> Unpin for LazyJoinQuery<'a, L, R>

§

impl<'a, L, R> UnwindSafe for LazyJoinQuery<'a, L, R>

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.