I am trying to write a function that accumulates numbers provided by a supplier for a given range starting from zero:
fn accumulate<F>(size: usize, supplier: F) -> Successors<f64, fn(&f64) -> Option<f64>>
where F: Fn(usize) -> f64 {
let mut range = 0..size;
successors(
Some(0.0),
|acc| range.next().map(|n| *acc + supplier(n)),
)
}
The error message is:
114 | |acc| range.next().map(|n| *acc + supplier(&config, n)),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found closure
This is strange because the successors function expects a closure, namely FnMut
. What am I doing wrong?