I'm trying to create a basic wrapper around a mesh to work with wgpu (more will be added later β abstracting this is justified), but I'm having some trouble with the lifetimes. This is what I have right now:
pub struct RenderableMesh{
pub buffer: Buffer,
pub count: u32
}
impl RenderableMesh{
pub fn render<'a, 'b>(&'a self, render_pass: &'b mut RenderPass<'b>) where 'b: 'a{
render_pass.set_vertex_buffer(0, &self.buffer, 0, 0);
render_pass.draw(0..self.count, 0..1);
}
}
Yet, this gives me an error:
|
76 | pub fn render<'a, 'b>(&'a self, render_pass: &'b mut RenderPass<'b>) where 'b: 'a{
| -------- ----------------------
| |
| these two types are declared with different lifetimes...
77 | render_pass.set_vertex_buffer(0, &self.buffer, 0, 0);
| ^^^^^^^^^^^^^^^^^ ...but data from `self` flows into `render_pass` here
The error seems to be saying that the code is malformed since render_pass
can store data from self
, and that self
may be dropped first, but the where 'b: 'a
part would seem to contradict that, since it (I think) says that render_pass
's lifetime is smaller than that of self
's. What's goign on here (is rustc's borrow checker unable to verify an otherwise valid program as I suspect)? How can I fix it?