I have a function that uses a closure as a parameter. My understanding is that FnMut
should be used here, but it doesn’t work. However, it works when I change it to Fn
. I hope someone can explain my mistake.
#![allow(unused)]
struct Data {
a: u32,
b: u64,
}
fn mark_label<F>(data: &mut Data, mark: F)
where F: FnMut(&mut Data) //if I change this line to F: Fn(&mut Data), it can work.
{
mark(data)
}
fn main() {
let mut data = Data {a: 1, b: 2};
mark_label(&mut data, |x| x.a = 2);
mark_label(&mut data, |x| x.b = 3);
}
1