pub struct LazyQuery<'a, T, I>{ /* private fields */ }Expand description
A lazy query builder that uses iterators for deferred execution.
Unlike the standard Query, LazyQuery doesn’t execute until you call
a terminal operation like .collect(), .count(), or .first().
§Benefits
- Deferred execution: No work until results needed
- Iterator fusion: Rust optimizes chained operations
- Early termination:
.take()stops as soon as enough items found - Composable: Build complex queries by composition
§Example
ⓘ
// Nothing executes yet
let query = LazyQuery::new(&products)
.where_(Product::price(), |&p| p < 100.0)
.where_(Product::stock(), |&s| s > 0);
// Execution happens here
let results: Vec<_> = query.collect();Implementations§
Source§impl<'a, T, I> LazyQuery<'a, T, I>
impl<'a, T, I> LazyQuery<'a, T, I>
Sourcepub fn where_<F, P>(
self,
path: KeyPaths<T, F>,
predicate: P,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_<F, P>( self, path: KeyPaths<T, F>, predicate: P, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn select_lazy<F>(
self,
path: KeyPaths<T, F>,
) -> impl Iterator<Item = F> + 'awhere
F: Clone + 'static,
I: 'a,
pub fn select_lazy<F>(
self,
path: KeyPaths<T, F>,
) -> impl Iterator<Item = F> + 'awhere
F: Clone + 'static,
I: 'a,
Sourcepub fn take_lazy(
self,
n: usize,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>where
I: 'a,
pub fn take_lazy(
self,
n: usize,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>where
I: 'a,
Sourcepub fn skip_lazy(
self,
n: usize,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>where
I: 'a,
pub fn skip_lazy(
self,
n: usize,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>where
I: 'a,
Source§impl<'a, T, I> LazyQuery<'a, T, I>
impl<'a, T, I> LazyQuery<'a, T, I>
Sourcepub fn min_by_float(self, path: KeyPaths<T, f64>) -> Option<f64>where
I: 'a,
pub fn min_by_float(self, path: KeyPaths<T, f64>) -> Option<f64>where
I: 'a,
Finds minimum float value (terminal operation).
Sourcepub fn max_by_float(self, path: KeyPaths<T, f64>) -> Option<f64>where
I: 'a,
pub fn max_by_float(self, path: KeyPaths<T, f64>) -> Option<f64>where
I: 'a,
Finds maximum float value (terminal operation).
Sourcepub fn where_after_systemtime(
self,
path: KeyPaths<T, SystemTime>,
reference: SystemTime,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_after_systemtime( self, path: KeyPaths<T, SystemTime>, reference: SystemTime, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_before_systemtime(
self,
path: KeyPaths<T, SystemTime>,
reference: SystemTime,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_before_systemtime( self, path: KeyPaths<T, SystemTime>, reference: SystemTime, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_between_systemtime(
self,
path: KeyPaths<T, SystemTime>,
start: SystemTime,
end: SystemTime,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_between_systemtime( self, path: KeyPaths<T, SystemTime>, start: SystemTime, end: SystemTime, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Source§impl<'a, T, I> LazyQuery<'a, T, I>
impl<'a, T, I> LazyQuery<'a, T, I>
Sourcepub fn where_after<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
reference: DateTime<Tz>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_after<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, reference: DateTime<Tz>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_before<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
reference: DateTime<Tz>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_before<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, reference: DateTime<Tz>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_between<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
start: DateTime<Tz>,
end: DateTime<Tz>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_between<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, start: DateTime<Tz>, end: DateTime<Tz>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_today<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
now: DateTime<Tz>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_today<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, now: DateTime<Tz>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_year<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
year: i32,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_year<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, year: i32, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_month<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
month: u32,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_month<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, month: u32, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_day<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
day: u32,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_day<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, day: u32, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_weekend<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_weekend<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_weekday<Tz>(
self,
path: KeyPaths<T, DateTime<Tz>>,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_weekday<Tz>( self, path: KeyPaths<T, DateTime<Tz>>, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Source§impl<'a, T, I> LazyQuery<'a, T, I>
impl<'a, T, I> LazyQuery<'a, T, I>
Sourcepub fn sum_timestamp(self, path: KeyPaths<T, i64>) -> i64where
I: 'a,
pub fn sum_timestamp(self, path: KeyPaths<T, i64>) -> i64where
I: 'a,
Sourcepub fn count_timestamp(self, path: KeyPaths<T, i64>) -> usizewhere
I: 'a,
pub fn count_timestamp(self, path: KeyPaths<T, i64>) -> usizewhere
I: 'a,
Sourcepub fn where_after_timestamp(
self,
path: KeyPaths<T, i64>,
reference: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_after_timestamp( self, path: KeyPaths<T, i64>, reference: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Filter by i64 timestamp being after a reference time (lazy).
§Arguments
path- The key-path to the i64 timestamp fieldreference- The reference timestamp to compare against
§Example
ⓘ
let recent = LazyQuery::new(&events)
.where_after_timestamp(Event::created_at_r(), cutoff_time)
.collect::<Vec<_>>();Sourcepub fn where_before_timestamp(
self,
path: KeyPaths<T, i64>,
reference: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_before_timestamp( self, path: KeyPaths<T, i64>, reference: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Filter by i64 timestamp being before a reference time (lazy).
§Arguments
path- The key-path to the i64 timestamp fieldreference- The reference timestamp to compare against
§Example
ⓘ
let old = LazyQuery::new(&events)
.where_before_timestamp(Event::created_at_r(), cutoff_time)
.collect::<Vec<_>>();Sourcepub fn where_between_timestamp(
self,
path: KeyPaths<T, i64>,
start: i64,
end: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_between_timestamp( self, path: KeyPaths<T, i64>, start: i64, end: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Filter by i64 timestamp being between two times (inclusive, lazy).
§Arguments
path- The key-path to the i64 timestamp fieldstart- The start timestampend- The end timestamp
§Example
ⓘ
let range = LazyQuery::new(&events)
.where_between_timestamp(Event::created_at_r(), start, end)
.collect::<Vec<_>>();Sourcepub fn where_last_days_timestamp(
self,
path: KeyPaths<T, i64>,
days: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_last_days_timestamp( self, path: KeyPaths<T, i64>, days: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_next_days_timestamp(
self,
path: KeyPaths<T, i64>,
days: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_next_days_timestamp( self, path: KeyPaths<T, i64>, days: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_last_hours_timestamp(
self,
path: KeyPaths<T, i64>,
hours: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_last_hours_timestamp( self, path: KeyPaths<T, i64>, hours: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_next_hours_timestamp(
self,
path: KeyPaths<T, i64>,
hours: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_next_hours_timestamp( self, path: KeyPaths<T, i64>, hours: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Sourcepub fn where_last_minutes_timestamp(
self,
path: KeyPaths<T, i64>,
minutes: i64,
) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
pub fn where_last_minutes_timestamp( self, path: KeyPaths<T, i64>, minutes: i64, ) -> LazyQuery<'a, T, impl Iterator<Item = &'a T> + 'a>
Trait Implementations§
Source§impl<'a, T, I> IntoIterator for LazyQuery<'a, T, I>
impl<'a, T, I> IntoIterator for LazyQuery<'a, T, I>
Auto Trait Implementations§
impl<'a, T, I> Freeze for LazyQuery<'a, T, I>where
I: Freeze,
impl<'a, T, I> RefUnwindSafe for LazyQuery<'a, T, I>where
I: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, I> Send for LazyQuery<'a, T, I>
impl<'a, T, I> Sync for LazyQuery<'a, T, I>
impl<'a, T, I> Unpin for LazyQuery<'a, T, I>where
I: Unpin,
impl<'a, T, I> UnwindSafe for LazyQuery<'a, T, I>where
I: UnwindSafe,
T: RefUnwindSafe,
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