1 A closure was used but didn't implement the expected trait.
3 Erroneous code example:
9 fn bar<T: Fn(u32)>(_: T) {}
13 let closure = |_| foo(x); // error: expected a closure that implements
14 // the `Fn` trait, but this closure only
15 // implements `FnOnce`
20 In the example above, `closure` is an `FnOnce` closure whereas the `bar`
21 function expected an `Fn` closure. In this case, it's simple to fix the issue,
22 you just have to implement `Copy` and `Clone` traits on `struct X` and it'll
26 #[derive(Clone, Copy)] // We implement `Clone` and `Copy` traits.
30 fn bar<T: Fn(u32)>(_: T) {}
34 let closure = |_| foo(x);
39 To better understand how these work in Rust, read the [Closures][closures]
42 [closures]: https://doc.rust-lang.org/book/ch13-01-closures.html