I am trying to create Cycle<Lines>> from a file at runtime but cannot figure out the correct lifetimes

I have a lazy_static block which is supposed to have a static iterator over some data so I can just get the next line.

lazy_static!{
    let rows:Cycle<Lines<'???>> = std::fs::read_to_string().unwrap_or_default().lines().cycle();
}

On the code above I have no clue where to get the lifetime for these lines.

Since it's available everywhere, the lifetime needs to be 'static.

But it is not 'static im reading it from a file at runtime

If the data read lives less than the entire remaining lifetime of the program after it's read ('static,) then you can't have it in lazy_static. lazy_static allows you to have 'static things that are created at runtime.

Oh my problem seems was the intermediate value being dropped when I was chaining things. When i use 2 different variables things seems to be working fine

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.