A callback is a function registered with another component so it can be invoked later when a particular event occurs. In embedded C libraries, this can connect an event such as a received UART byte to Rust code. section 8.4.2
// callback_lib.h #ifndef CALLBACK_LIB_H #define CALLBACK_LIB_H // A type alias for "a function that takes an int and returns nothing." // This is what a callback looks like from C's point of view: just a // pointer to a function with this signature. typedef void (*callback_t)(int); // Lets someone hand this library a function to call later. void register_callback(callback_t cb); // Fires whichever function was last registered, passing it `value`. void trigger_callback(int value); #endif
The C declaration uses a function pointer for the callback and provides a registration function for storing it. section 8.4.2
Calling a Rust callback from C
A Rust function declared with the C calling convention can be registered with the C library. The library invokes it later when its event occurs; registration itself does not trigger the callback. section 8.4.2






















