pub fn from_fn<St, F>(state: St, f: Covar<F>) -> FromFn<St, F>where
F: for<'all> FnMutHKAOpt<'all, &'all mut St>,Expand description
Creates a lender from a state and a closure
F: FnMut(&mut St) -> Option<T>.
Note that functions passed to this function must be built
using the covar! or covar_mut!
macros, which also check for covariance of the returned type.
ยงExamples
let mut lender = lender::from_fn(0,
covar_mut!(for<'all>
|state: &'all mut i32|
-> Option<&'all mut i32> {
if *state < 10 {
*state += 1;
Some(state)
} else {
None
}
}));
assert_eq!(lender.next(), Some(&mut 1));