fn main() {
let mut x = String::new();
let y = || {
let t = x;
};
let mut ww = Box::new(y);
ww();
}
I expect it to run without any error as this implementation exist
impl<Args, F, A> FnOnce<Args> for Box<F, A>
But I am getting some weird errors which I am unable to understand why?
error[E0525]: expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
--> src/main.rs:22:13
|
22 | let y = || {
| ^^ this closure implements `FnOnce`, not `FnMut`
23 | let t = x;
| - closure is `FnOnce` because it moves the variable `x` out of its environment
...
26 | ww();
| ---- the requirement to implement `FnMut` derives from here
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
--> src/main.rs:22:13
|
22 | let y = || {
| ^^ this closure implements `FnOnce`, not `Fn`
23 | let t = x;
| - closure is `FnOnce` because it moves the variable `x` out of its environment
...
26 | ww();
| ---- the requirement to implement `Fn` derives from here