Hi, folks! I'm stuck in a lifetime problem.
I can't understand, all variables are declared in the same function and I suppose that have the same lifetime
Here is the code:
fn main() {
let candles = Vec::new();
let candles_ref = candles.as_slice();
let indicator_provider = IndicatorProvider::new(candles_ref);
let macd_trend = MacdTrend::new(indicator_provider);
let mut trader = Trader::new(Box::new(macd_trend));
trader.check(candles_ref);
}
The error is this:
error[E0597]: `trader` does not live long enough
--> src/main.rs:54:5
|
54 | trader.check(candles_ref);
| ^^^^^^ borrowed value does not live long enough
55 | }
| -
| |
| `trader` dropped here while still borrowed
| borrow might be used here, when `trader` is dropped and runs the destructor for type `Trader<'_>`
error: aborting due to previous error
The playground is here: Rust Playground
I tried a lot of combinations, removing + 'a
of Trait Box, using two lifetimes like 'a: 'b
and other things.
How I can resolve this error in this code?
I appreciate any help! Thank you.