pub fn from_fallible_fn<St, E, F>(state: St, f: Covar<F>) -> FromFn<St, E, F>where
F: for<'all> FnMutHKAResOpt<'all, &'all mut St, E>,Expand description
Creates a fallible lender from a state and a closure
F: FnMut(&mut St) -> Result<Option<T>, E>.
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_fallible_fn::<_, Error, _>(
0,
covar_mut!(for<'all>
|state: &'all mut i32|
-> Result<Option<&'all mut i32>, Error> {
if *state < 3 {
*state += 1;
Ok(Some(state))
} else {
Ok(None)
}
})
);
assert_eq!(lender.next().unwrap(), Some(&mut 1));