pub fn optional<'outer, S, R>(
f: impl for<'inner> FnOnce(&mut Optional<'outer, 'inner, S>) -> R,
) -> R
Expand description
This is a combinator function that allows constructing single row optional queries.
let res = txn.query_one(optional(|row| {
let x = row.and(Some("test"));
let y = row.and(Some(42));
row.then((x, y))
}));
assert_eq!(res, Some(("test".to_owned(), 42)));
let res = txn.query_one(optional(|row| {
let x = row.and(Some("test"));
let y = row.and(None::<i64>);
row.then((x, y))
}));
assert_eq!(res, None);