I am a bit confused by Option::map()
. The documentation says it accepts a FnOnce
.
If so, why do a
and b
cause compilations errors?
let mut v = 3;
let mut a: &FnOnce(u32) -> u32 = &|x: u32| { v = x; x };
let mut b: &FnMut(u32) -> u32 = &|x: u32| { x };
let mut c: &Fn(u32) -> u32 = &|x: u32| { x };
let o = Option::Some(3);
o.map(a); // trait bound `std::ops::FnOnce(u32) -> u32: std::ops::Fn<(u32,)>` is not satisfied
o.map(b); // trait bound `std::ops::FnMut(u32) -> u32: std::ops::Fn<(u32,)>` is not satisfied
o.map(c); // works
Shouldn't all of them, including a
and b
, implement FnOnce
according to this post?