I’ve just added a page on doing callbacks and function pointers to this FFI guide I’m working on and was wanting some feedback.
I’ve tried to represent a semi-realistic scenario where you’re using some C library that will run an expensive computation and lets you give it a callback to run on the intermediate results (allowing you to monitor the computation and abort it early).
Then as the second part I’ve changed the callback a bit to use a struct method so you can keep track of what happened each time the callback was called.
In particular I’m wondering:
- Is this example something realistic you might see/do when interacting with other libraries across the FFI boundary?
- Can it be improved or altered to make the concept easier to understand (and prevent unnecessary footguns)?
- Can you see any typos, ambiguous wording, or other grammatical errors?