macro_rules! covar {
($($t:tt)+) => { ... };
}Expand description
Covariance-checked Fn closure macro.
Creates a Covar-wrapped closure with explicit lifetime bounds and a
compile-time covariance check (when a return type is specified with
for<'a> bounds). This ensures that the return type is covariant in the
bound lifetime, which is required for soundness with lending iterators.
Use covar! when the closure only needs shared access to its captures
(&self semantics) and may be called multiple times. In practice,
covar_mut! is more commonly used since most lender
methods require FnMut.
§Syntax
covar!(for<'a> |arg: Type<'a>| -> ReturnType<'a> { body })
covar!(for<'a> move |arg: Type<'a>| -> ReturnType<'a> { body })§Examples
let data = [1, 2, 3];
let lender = data.iter().into_lender();
let mapped = lender.map(
covar!(for<'lend> |x: &'lend i32| -> i32 { *x * 2 }),
);