Just mark it with '_
, 'a
or 'static
and hope one of them works was my first go-to solutions when dealign with rust borrow checker. I had no clue what lifetimes meant to represent, or how their values are inferred since unlike type generics there's not a single point where the type can be inferred from the context.
let mut values = Vec::new();
values.push(Route { path: "/home" });
There, the second line calls Vec::push(&mut self, value: T)
function with a value of Route { path: "/home" }
which is an instance of the type Route
. There compiler can infer that the type argument T
can be implicitly set to Route
and fill the missing gaps for us. You might be thinking, what if you wanted to store different implementations of Route
, aka how does it deal with inheritance. The answer is, we don't need to worry about that because rust doesn't have a concept of inheritance. As a matter of fact, it is completely unnecessary in this context, since we are dealing with data not