pub struct LockLazyQuery<'a, T: 'static, L, I>{ /* private fields */ }Expand description
Lazy query for locked data with early termination.
Implementations§
Source§impl<'a, T: 'static, L, I> LockLazyQuery<'a, T, L, I>
impl<'a, T: 'static, L, I> LockLazyQuery<'a, T, L, I>
Sourcepub fn where_<F, P>(
self,
path: KeyPaths<T, F>,
predicate: P,
) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
pub fn where_<F, P>( self, path: KeyPaths<T, F>, predicate: P, ) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
Filter using a key-path predicate (lazy).
Sourcepub fn select_lazy<F>(
self,
path: KeyPaths<T, F>,
) -> impl Iterator<Item = F> + 'awhere
F: Clone + 'static,
pub fn select_lazy<F>(
self,
path: KeyPaths<T, F>,
) -> impl Iterator<Item = F> + 'awhere
F: Clone + 'static,
Map to a field value (lazy).
This allows you to select only specific fields from locked data without cloning the entire object. Perfect for projecting data efficiently.
§Example
// Select only product names (not full objects)
let names: Vec<String> = products
.lock_lazy_query()
.where_(Product::price_r(), |&p| p > 100.0)
.select_lazy(Product::name_r())
.collect();
// Select only IDs
let ids: Vec<u32> = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.select_lazy(Product::id_r())
.take(10)
.collect();
// Select prices and compute sum
let total: f64 = products
.lock_lazy_query()
.where_(Product::category_r(), |c| c == "Electronics")
.select_lazy(Product::price_r())
.sum();Performance Note: This is much more efficient than collecting full objects and then extracting fields, as it only clones the specific field value.
Sourcepub fn take_lazy(self, n: usize) -> impl Iterator<Item = T> + 'awhere
T: Clone,
pub fn take_lazy(self, n: usize) -> impl Iterator<Item = T> + 'awhere
T: Clone,
Take first N items (lazy).
Sourcepub fn skip_lazy(
self,
n: usize,
) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
pub fn skip_lazy( self, n: usize, ) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
Skip first N items (lazy).
Sourcepub fn sum<F>(self, path: KeyPaths<T, F>) -> F
pub fn sum<F>(self, path: KeyPaths<T, F>) -> F
Sum a numeric field (terminal).
Efficiently computes the sum without collecting all items into a Vec first.
§Example
// Sum all prices
let total_value: f64 = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.sum(Product::price_r());
// Sum stock quantities
let total_stock: u32 = products
.lock_lazy_query()
.where_(Product::category_r(), |c| c == "Electronics")
.sum(Product::stock_r());Sourcepub fn avg(self, path: KeyPaths<T, f64>) -> Option<f64>
pub fn avg(self, path: KeyPaths<T, f64>) -> Option<f64>
Calculate average of f64 field (terminal).
Returns None if no items match.
§Example
let avg_price = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.avg(Product::price_r());
match avg_price {
Some(avg) => println!("Average price: ${:.2}", avg),
None => println!("No items found"),
}Sourcepub fn exists(self) -> bool
pub fn exists(self) -> bool
Check if any items exist matching the criteria (terminal).
Alias for any(), provides SQL-like EXISTS semantics.
Stops at the first match - very efficient!
§Example
let has_expensive = products
.lock_lazy_query()
.where_(Product::price_r(), |&p| p > 1000.0)
.exists();
if has_expensive {
println!("We have luxury items!");
}
// SQL equivalent: SELECT EXISTS(SELECT 1 FROM products WHERE price > 1000)Sourcepub fn limit(self, n: usize) -> impl Iterator<Item = T> + 'awhere
T: Clone,
pub fn limit(self, n: usize) -> impl Iterator<Item = T> + 'awhere
T: Clone,
Limit results to first N items (lazy).
Alias for creating a limited iterator. Use with .collect() or .all().
§Example
let top_5: Vec<Product> = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 10)
.limit(5)
.collect();
// SQL equivalent: SELECT * FROM products WHERE stock > 10 LIMIT 5Sourcepub fn distinct<F>(self, path: KeyPaths<T, F>) -> Vec<F>
pub fn distinct<F>(self, path: KeyPaths<T, F>) -> Vec<F>
Get distinct values for a field (terminal).
Returns a Vec of unique field values. Uses HashSet internally.
§Example
let categories: Vec<String> = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.distinct(Product::category_r());
println!("Available categories: {:?}", categories);
// SQL equivalent: SELECT DISTINCT category FROM products WHERE stock > 0Sourcepub fn all_match<F, P>(self, path: KeyPaths<T, F>, predicate: P) -> bool
pub fn all_match<F, P>(self, path: KeyPaths<T, F>, predicate: P) -> bool
Check if all items match a predicate (terminal).
Returns true if all items match, false otherwise. Short-circuits on first non-match.
§Example
let all_in_stock = products
.lock_lazy_query()
.where_(Product::category_r(), |c| c == "Electronics")
.all_match(Product::stock_r(), |&s| s > 0);
if all_in_stock {
println!("All electronics are in stock!");
}Sourcepub fn count_where<F, P>(self, path: KeyPaths<T, F>, predicate: P) -> usize
pub fn count_where<F, P>(self, path: KeyPaths<T, F>, predicate: P) -> usize
Sourcepub fn where_after_systemtime(
self,
path: KeyPaths<T, SystemTime>,
reference: SystemTime,
) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
pub fn where_after_systemtime( self, path: KeyPaths<T, SystemTime>, reference: SystemTime, ) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
Sourcepub fn where_before_systemtime(
self,
path: KeyPaths<T, SystemTime>,
reference: SystemTime,
) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
pub fn where_before_systemtime( self, path: KeyPaths<T, SystemTime>, reference: SystemTime, ) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
Sourcepub fn where_between_systemtime(
self,
path: KeyPaths<T, SystemTime>,
start: SystemTime,
end: SystemTime,
) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
pub fn where_between_systemtime( self, path: KeyPaths<T, SystemTime>, start: SystemTime, end: SystemTime, ) -> LockLazyQuery<'a, T, L, impl Iterator<Item = &'a L> + 'a>
Sourcepub fn order_by<F>(self, path: KeyPaths<T, F>) -> Vec<T>
pub fn order_by<F>(self, path: KeyPaths<T, F>) -> Vec<T>
Orders results by a field in ascending order (terminal).
Note: This method requires T: Clone as it creates owned sorted copies.
This is a terminal operation that collects and sorts all matching items.
§Arguments
path- The key-path to the field to order by
§Example
let sorted = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.order_by(Product::name_r());Sourcepub fn order_by_desc<F>(self, path: KeyPaths<T, F>) -> Vec<T>
pub fn order_by_desc<F>(self, path: KeyPaths<T, F>) -> Vec<T>
Orders results by a field in descending order (terminal).
Note: This method requires T: Clone as it creates owned sorted copies.
This is a terminal operation that collects and sorts all matching items.
§Arguments
path- The key-path to the field to order by
§Example
let sorted = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.order_by_desc(Product::stock_r());Sourcepub fn order_by_float(self, path: KeyPaths<T, f64>) -> Vec<T>where
T: Clone,
pub fn order_by_float(self, path: KeyPaths<T, f64>) -> Vec<T>where
T: Clone,
Orders results by a float field in ascending order (terminal).
Note: This method requires T: Clone as it creates owned sorted copies.
This is a terminal operation that collects and sorts all matching items.
§Arguments
path- The key-path to the f64 field to order by
§Example
let sorted = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.order_by_float(Product::price_r());Sourcepub fn order_by_float_desc(self, path: KeyPaths<T, f64>) -> Vec<T>where
T: Clone,
pub fn order_by_float_desc(self, path: KeyPaths<T, f64>) -> Vec<T>where
T: Clone,
Orders results by a float field in descending order (terminal).
Note: This method requires T: Clone as it creates owned sorted copies.
This is a terminal operation that collects and sorts all matching items.
§Arguments
path- The key-path to the f64 field to order by
§Example
let sorted = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.order_by_float_desc(Product::rating_r());Sourcepub fn group_by<F>(self, path: KeyPaths<T, F>) -> HashMap<F, Vec<T>>
pub fn group_by<F>(self, path: KeyPaths<T, F>) -> HashMap<F, Vec<T>>
Groups results by a field value (terminal).
Note: This method requires T: Clone as it creates owned copies in groups.
This is a terminal operation that collects all matching items into groups.
§Arguments
path- The key-path to the field to group by
§Example
let by_category = products
.lock_lazy_query()
.where_(Product::stock_r(), |&s| s > 0)
.group_by(Product::category_r());
for (category, products) in by_category {
println!("{}: {} products", category, products.len());
}
// SQL equivalent: SELECT * FROM products WHERE stock > 0 GROUP BY category