Relative Content

Tag Archive for rustlifetime

Define lifetime for associative type without lifetime bound

I am implementing FromStr for a type and for the error I want to return the passed &str inside a wrapper struct. However, this requires the the struct to have a lifetime bound for the &str but that will cause errors inside FromStr since its associative type Err does not have any lifetime bounds and cannot be modified either. Lastly, it’s not possible to add a lifetime bound to the impl since it does not get constrained by anything, at least in the ways I have tried. So, how can I squeeze in my wrapper into the associative type?

Question about Rust lifetimes when implementing the Iterator trait

I’m having some issue figuring out a lifetime error I’m getting when trying to implement the Iterator trait on a struct internally storing a reference. I have simplified the code a bit, hopefully I haven’t omitted something important, but it looks like this:

Why can’t i borrow a reference to a lifetime object in a closure?

I am new to rust and I am trying to write a struct which stores a tabular data in a Vec<(String,u32)> format. But I also need it to be exposed in a columnar format i.e. I need two separate data members name: Vec<&mut String> and rating: Vec<&mut u32>. When trying the following though I am facing an issue with rust complaining about a lifetime issue.

Rust: Parameter type may not live long enough

the parameter type T may not live long enough
the parameter type T must be valid for the static lifetime…rustcClick for full compiler diagnostic
mod.rs(45, 13): consider adding an explicit lifetime bound: : 'static