-impl rustEventsProvider for EventsProvider {
- fn get_and_clear_pending_events(&self) -> Vec<lightning::util::events::Event> {
- let mut ret = (self.get_and_clear_pending_events)(self.this_arg);
- let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); };
- local_ret
+/// Calls the free function if one is set
+#[no_mangle]
+pub extern "C" fn EventsProvider_free(this_ptr: EventsProvider) { }
+impl Drop for EventsProvider {
+ fn drop(&mut self) {
+ if let Some(f) = self.free {
+ f(self.this_arg);
+ }
+ }
+}
+/// A trait implemented for objects handling events from [`EventsProvider`].
+#[repr(C)]
+pub struct EventHandler {
+ /// An opaque pointer which is passed to your function implementations as an argument.
+ /// This has no meaning in the LDK, and can be NULL or any other value.
+ pub this_arg: *mut c_void,
+ /// Handles the given [`Event`].
+ ///
+ /// See [`EventsProvider`] for details that must be considered when implementing this method.
+ pub handle_event: extern "C" fn (this_arg: *const c_void, event: crate::lightning::util::events::Event),
+ /// Frees any resources associated with this object given its this_arg pointer.
+ /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
+ pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
+}
+
+use lightning::util::events::EventHandler as rustEventHandler;
+impl rustEventHandler for EventHandler {
+ fn handle_event(&self, mut event: lightning::util::events::Event) {
+ (self.handle_event)(self.this_arg, crate::lightning::util::events::Event::native_into(event))