Cloning of closures


#1

Why is it not possible to clone closure in rust?

Assuming the arguments and captured variables all implement Clone I think this should be possible.

In fact if it should probably even be possible to Copy it (If the captured values implement Copy and unless that is impossible for non Sized types).

Heres an example of code that fails to compile:

fn main() {
    let sub = |a: i32, b: i32| { a - b };
    let sub2 = sub.clone();
}

The only topic I found related to this was

I’m unsure why its marked as depricated and i’m a bit reluctant on replying to a 3 year old topic.

I’m still not very familiar with some rust semantics so im sorry if I missed something obvious.

Not sure which category to put this in, Internals?


#2

You may be looking for this issue.


#3

Thats exactly what im looking for, i dont know how that didn’t show up when i searched for it