Skip to content

Instantly share code, notes, and snippets.

@azriel91
Last active December 17, 2016 02:42
Show Gist options
  • Save azriel91/82e08a364bd91dfcf5bb087c5c44f071 to your computer and use it in GitHub Desktop.
Save azriel91/82e08a364bd91dfcf5bb087c5c44f071 to your computer and use it in GitHub Desktop.
Minimal example to reproduce issue
trait Task {}
trait Display {}
struct SomethingTask<'d> {
displays: Vec<&'d Display>,
}
impl<'d> Task for SomethingTask<'d> {}
struct MyDisplay;
impl Display for MyDisplay {}
struct Engine {
tasks: Vec<Box<Task>>,
}
fn main() {
let my_display = MyDisplay;
let displays = vec![&my_display as &Display];
// ^^^^^^^^^^ does not live long enough
let task: Box<Task> = Box::new(SomethingTask { displays: displays });
let tasks = vec![task];
Engine { tasks: tasks };
}
// - borrowed value only lives until here
// = note: borrowed value must be valid for the static lifetime...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment