Hello everyone! I am trying to build non-static function over the static one:
type VertexShader = Fn(AppVertex) -> GeometryVertex;
type VertexShaderSource = fn(AppVertex, transoform: na::Matrix4<f32>) -> GeometryVertex;
impl VertexPipe {
...
fn build_shader(&self, source: &'static VertexShaderSource) -> Box<VertexShader> {
Box::new(|app_vertex| source(app_vertex, na::Matrix4::<f32>::identity()))
}
...
}
And compiler says that I am borrowing source because that function owns it:
error[E0373]: closure may outlive the current function, but it borrows `source`, which is owned by the current function
--> src/main.rs:47:18
|
47 | Box::new(|app_vertex| source(app_vertex, na::Matrix4::<f32>::identity()))
| ^^^^^^^^^^^^ ------ `source` is borrowed here
| |
| may outlive borrowed value `source`
How I can copy reference to the closure? Why rust doesn't automatically?