nebgnahz / cv-rs

Rust wrapper for OpenCV (manual at this point)
https://nebgnahz.github.io/cv-rs/cv/
MIT License
203 stars 41 forks source link

Accept closures in highgui_set_mouse_callback #118

Open vadixidav opened 5 years ago

vadixidav commented 5 years ago

In highgui_set_mouse_callback currently it is not possible to pass it a closure. By storing an arbitrary dyn Fn type in the Box inside its definition, it should be possible to accept an arbitrary closure to ease callback handling.

Pzixel commented 5 years ago

Making <F: FnMut> would be enough.

vadixidav commented 5 years ago

@Pzixel That is true, but we then have to turn it into a dyn FnMut so that we can pass it to C as a single pointer type since the type is erased. We will find out if we can use FnMut based on if any data races can occur in the code. I think there is a good chance we can accept FnMut. We can only do that if the C code never creates a data race. If it does then we will need to use Fn. If C makes a cross thread data race then we will also need to force it to be Send and Sync.

vadixidav commented 5 years ago

I actually already fixed this in #117. Once that is merged we can close this.