//@ run-pass struct State; type Error = (); trait Bind { //~ WARN trait `Bind` is never used type Output; fn bind(self, f: F) -> Self::Output; } fn bind(mut a: A, mut f: F) -> impl FnMut(&mut State) -> Result where F: FnMut(T) -> B, A: FnMut(&mut State) -> Result, B: FnMut(&mut State) -> Result { move |state | { let r = a(state)?; f(r)(state) } } fn atom(x: T) -> impl FnMut(&mut State) -> Result { let mut x = Some(x); move |_| x.take().map_or(Err(()), Ok) } fn main() { assert_eq!(bind(atom(5), |x| atom(x > 4))(&mut State), Ok(true)); }