Hello,
Sorry to bother you but I have an error on my rust code. I use the Piston crate and I want to put a Piston Window in a struct so I did that but it does not work.
use std::collections::HashMap;
use opengl_graphics::{TextureSettings,OpenGL};
use piston_window::{Texture,G2dTexture,PistonWindow,Event};
use crate::Traits::Drawable;
use piston_window::WindowSettings;
pub struct GameRenderer {
txt_map: HashMap<&'static str,&'static G2dTexture>,
window: &'static PistonWindow,
scene_map: HashMap<&'static str,&'static G2dTexture>,
}
impl Drawable for GameRenderer {
fn draw(&mut self,window: &mut GameRenderer,e: &Event) {
}
}
impl GameRenderer {
pub fn new(x: u32,y: u32,title: &str) -> GameRenderer {
let opengl = OpenGL::V3_2;
let mut window: &'static PistonWindow = &mut(
WindowSettings::new(title, [x, y])
.exit_on_esc(true)
.opengl(opengl)
.vsync(true)
.resizable(false)
.decorated(true)
.build()
.unwrap());
return GameRenderer{window: window,scene_map: HashMap::new(),txt_map: HashMap::new()};
}
}
And the error
--> src/GameRenderer.rs:25:53
|
25 | let mut window: &'static PistonWindow = &mut(
| _________________________---------------------_______^
| | |
| | type annotation requires that borrow lasts for `'static`
26 | | WindowSettings::new(title, [x, y])
27 | | .exit_on_esc(true)
28 | | .opengl(opengl)
... |
32 | | .build()
33 | | .unwrap());
| |__________________________^ creates a temporary which is freed while still in use
34 | return GameRenderer{window: window,scene_map: HashMap::new(),txt_map: HashMap::new()};
35 | }
| - temporary value is freed at the end of this statement
Thanks in advance for the answer.
ccgauche.
Excuse me for the quality of my english but I am french