Why compiler say :
error: `game` does not live long enough
--> src\main.rs:4:62
|
4 | let card = Card { feature : Box::new(ColorFeature { g : &game})};
| ^^^^ does not live long enough
5 | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
Code is below:
fn main() {
let game = Game { };
let card = Card { feature : Box::new(ColorFeature { g : &game})};
}
struct Card {
feature : Box<Feature>
}
trait Feature {
}
struct ColorFeature<'a> {
g : &'a Game
}
impl<'a> Feature for ColorFeature<'a> {
}
struct Game {
}