Skip to main content

once_with

Function once_with 

Source
pub fn once_with<St, F>(state: St, f: Covar<F>) -> OnceWith<St, F>
where F: for<'all> FnOnceHKA<'all, &'all mut St>,
Expand description

Creates a lender that lazily generates a value exactly once by invoking the provided closure.

Note that functions passed to this function must be built using the covar!, covar_mut!, or covar_once! macros, which also check for covariance of the returned type.

ยงExamples

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