Skip to main content

covar_once

Macro covar_once 

Source
macro_rules! covar_once {
    ($($t:tt)+) => { ... };
}
Expand description

Covariance-checked FnOnce 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_once! when the closure will only be called once (e.g., with Lender::fold). For closures that may be called multiple times, use covar_mut! or covar!.

§Syntax

covar_once!(for<'a> |arg: Type<'a>| -> ReturnType<'a> { body })
covar_once!(for<'a> move |arg: Type<'a>| -> ReturnType<'a> { body })

§Examples

let mut lender = lender::once_with(42,
    covar_once!(for<'lend> |state: &'lend mut i32| -> &'lend mut i32 {
        *state += 1;
        state
    })
);
assert_eq!(lender.next(), Some(&mut 43));
assert_eq!(lender.next(), None);