panda/
callbacks.rs

1use crate::sys::panda_cb_type;
2
3mod closure;
4mod export;
5pub use closure::{set_plugin_ref, Callback};
6pub use export::CallbackReturn;
7
8mod ppp_closures;
9pub use ppp_closures::{
10    InternalPppClosureCallback, PppCallback, __internal_install_ppp_closure_callback,
11};
12
13/// An opaque type used to register/unregister callbacks with PANDA. Passed into init/unit
14/// callbacks
15pub struct PluginHandle;
16
17/// A typeless PANDA callback used internally by callback attributes. Not recommended for direct
18/// use.
19#[doc(hidden)]
20pub struct InternalCallback {
21    pub cb_type: panda_cb_type,
22    pub fn_pointer: *const (),
23}
24
25impl InternalCallback {
26    pub fn new(cb_type: panda_cb_type, fn_pointer: *const ()) -> Self {
27        Self {
28            cb_type,
29            fn_pointer,
30        }
31    }
32}
33
34/// A callback set to run on plugin uninit. To add an uninit callback use `#[panda::uninit]` on a
35/// function which takes an `&mut PluginHandle` as an argument.
36///
37/// ### Example
38///
39/// ```rust
40/// use panda::PluginHandle;
41///
42/// #[panda::uninit]
43/// fn on_exit(plugin: &mut PluginHandle) {
44///     // Do stuff
45/// }
46/// ```
47pub struct UninitCallback(pub fn(&mut PluginHandle));
48
49#[doc(hidden)]
50pub struct PPPCallbackSetup(pub fn());
51
52inventory::collect!(InternalCallback);
53inventory::collect!(UninitCallback);
54inventory::collect!(PPPCallbackSetup);