I am trying to write code for a Runge-Kutta solver, with the idea that it should solve ODE on "big" object and hence should be generic and not use copy at every line. I have a lifetime issue which I have brought done to the following MCVE (playground):
use std::ops;
fn step<'a, 'b, Y, F>(f: F, y: &'a Y, t: f64) -> ()
where
'a: 'b,
F: Fn(&Y, f64) -> Y,
f64: ops::Mul<&'b Y, Output = Y>,
{
let k0 = f(y, t);
let foo = 1. / 5. * &k0;
}
I get the following lifetime error, which I just can't seem to solve. Could you help me break done what is happening ?
error[E0597]: `k0` does not live long enough
--> src/lib.rs:10:25
|
3 | fn step<'a, 'b, Y, F>(f: F, y: &'a Y, t: f64) -> ()
| -- lifetime `'b` defined here
...
10 | let foo = 1. / 5. * &k0;
| ^^^
| |
| borrowed value does not live long enough
| requires that `k0` is borrowed for `'b`
11 | }
| - `k0` dropped here while still borrowed