my code
pub struct PistonRenderContext<'a> {
c: Context,
g: &'a mut G2d<'a>,
arguments: &'a RenderArgs,
device: &'a gfx_device_gl::Device,
}
impl<'a> PistonRenderContext<'a> {
fn new(
c: Context,
g: &'a mut G2d<'a>,
arguments: &'a RenderArgs,
device: &'a mut gfx_device_gl::Device,
) -> PistonRenderContext<'a> {
PistonRenderContext{c, g, arguments, device }
}
}
// within some function
Loop::Render(render_args) => {
self.window.draw_2d(&event, |c, g, device| {
clear([1.0; 4], g);
let ctx = PistonRenderContext::new(c, g, &render_args, device);
game.render(&ctx, resources);
});
}
the error :
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> src/abstraction/piston_abstraction.rs:94:31
|
94 | let ctx = PistonRenderContext::new(c, g, &render_args, device);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #4 defined on the body at 92:45...
--> src/abstraction/piston_abstraction.rs:92:45
|
92 | self.window.draw_2d(&event, |c, g, device| {
| _____________________________________________^
93 | | clear([1.0; 4], g);
94 | | let ctx = PistonRenderContext::new(c, g, &render_args, device);
95 | | game.render(&ctx, resources);
96 | | });
| |_________________^
note: ...so that reference does not outlive borrowed content
--> src/abstraction/piston_abstraction.rs:94:76
|
94 | let ctx = PistonRenderContext::new(c, g, &render_args, device);
| ^^^^^^
note: but, the lifetime must be valid for the anonymous lifetime #3 defined on the body at 92:45...
--> src/abstraction/piston_abstraction.rs:92:45
|
92 | self.window.draw_2d(&event, |c, g, device| {
| _____________________________________________^
93 | | clear([1.0; 4], g);
94 | | let ctx = PistonRenderContext::new(c, g, &render_args, device);
95 | | game.render(&ctx, resources);
96 | | });
| |_________________^
note: ...so that the expression is assignable
--> src/abstraction/piston_abstraction.rs:94:59
|
94 | let ctx = PistonRenderContext::new(c, g, &render_args, device);
| ^
= note: expected `&mut gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>`
found `&mut gfx_graphics::back_end::GfxGraphics<'_, gfx_device_gl::Resources, gfx_device_gl::command::CommandBuffer>`
error: aborting due to previous error; 2 warnings emitted
I do not understand the error and I do not understand why the thing do not work
In my opinion lifetime is completely fine