Function aggregate

Source
pub fn aggregate<'outer, S, F, R>(f: F) -> R
where F: for<'inner> FnOnce(&mut Aggregate<'outer, 'inner, S>) -> R,
Expand description

Perform an aggregate that returns a single result for each of the current rows.

You can filter the rows in the aggregate based on values from the outer query. That is the only way to get a different aggregate for each outer row.

let res = txn.query_one(aggregate(|rows| {
    let user = rows.join(User);
    rows.count_distinct(user)
}));
assert_eq!(res, 1, "there is one user in the database");