ros2_rust
ros2_rust copied to clipboard
Use Fn or FnMut for callbacks?
Services and Subscriptions should have the same trait bounds on their callbacks. It can be either Fn or FnMut. Fn callbacks can run concurrently with themselves without synchronization, but FnMut callbacks allow more operations inside the callback.
I wouldn't characterize it as FnMut allowing more operations. You would just need to wrap your operations inside of some kind of Mutex and Cell or RefCell.
The FnMut is more convenient for the user in some specific scenarios, but the above techniques will probably be necessary as soon as callbacks are operating on shared data anyway.
OK, so seems like the consensus is more towards Fn, correct @jhdcs @esteve? It's fine to move to Fn with me.