I am writing a graphical program in Rust using the sdl2 crate from crates.io.
I have created this struct in main.rs
:
struct GameObject {
name: &'static str,
pub texture: Option<Texture<'static>>
}
impl GameObject {
pub fn new(name: &'static str) -> Self {
Self { name, texture: None }
}
pub fn set_texture(&mut self, t: Option<Texture<'static>>) {
self.texture = t;
}
}
I am trying to add a texture to an instance of GameObject
with the following lines of code (where canvas
is the result of window.into_canvas().build().unwrap()
on my main window):
let tc = canvas.texture_creator();
let mut g = GameObject::new("obj");
g.texture = Some(tc.load_texture("image.png").unwrap());
which causes this error:
error[E0597]: `tc` does not live long enough
--> src/main.rs:30:22
|
30 | g.texture = Some(tc.load_texture("image.png").unwrap());
| ^^---------------------------
| |
| borrowed value does not live long enough
| argument requires that `tc` is borrowed for `'static`
What does this mean in the context of my program?