5 ms·
My personal nightmare is Fn, FnMut, and FnOnce. I always got them in the opposite order as I intended.
by low_tech_punk 4y ago
My personal nightmare is Fn, FnMut, and FnOnce. I always got them in the opposite order as I intended.
- estebank 4y agoIf when trying to use them the compiler fails to provide adequate feedback to get you on track, please file diagnostics tickets! We take them seriously.
- ssokolow 4y agoI think they're saying that it's counter-intuitive that the specialization relationship between Fn, FnMut, and FnOnce is the reverse of foo, &mut foo, and &foo. I know it took me a long time for that to stick.
- conradludgate 4y agoFn: a function that can be called many times without side effects. Can be shared. Almost exactly like regular functions besides the capturing. FnMut: a function that can be called many times but can have side effects, because of this it must be exclusively held (&mut F) FnOnce: a function that can be called only once, making use of by-ownership function calls So I remember it like Fn: just a function FnMut: a function that needs &mut access FnOnce: only used once, moving ownership