I have a struct which looks something like this:
pub struct MyStruct
where
F: Fn(usize) -> f64,
{
field: usize,
mapper: F,
// fie
As of Rust 1.26.0, closures implement both Copy
and Clone
if all of the captured variables do:
#[derive(Clone)]
pub struct MyStruct
where
F: Fn(usize) -> f64,
{
field: usize,
mapper: F,
}
fn main() {
let f = MyStruct {
field: 34,
mapper: |x| x as f64,
};
let g = f.clone();
println!("{}", (g.mapper)(3));
}