Skip to content

Commit 1beb3bb

Browse files
committed
Add a bindings-only version of Future::register_callback
While we could, in theory, add support to the bindings logic to map `Box<dyn Trait>`, there isn't a whole lot of use doing so when its incredibly trivial to do directly. This adds a trivial wrapper around `Future::register_callback` that is only built in bindings and which is linked in the `register_callback` docs for visibility.
1 parent 3b7859f commit 1beb3bb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/util/wakers.rs

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ pub struct Future {
163163
impl Future {
164164
/// Registers a callback to be called upon completion of this future. If the future has already
165165
/// completed, the callback will be called immediately.
166+
///
167+
/// (C-not exported) use the bindings-only `register_callback_fn` instead
166168
pub fn register_callback(&self, callback: Box<dyn FutureCallback>) {
167169
let mut state = self.state.lock().unwrap();
168170
if state.complete {
@@ -172,6 +174,16 @@ impl Future {
172174
state.callbacks.push(callback);
173175
}
174176
}
177+
178+
// C bindings don't (currently) know how to map `Box<dyn Trait>`, and while it could add the
179+
// following wrapper, doing it in the bindings is currently much more work than simply doing it
180+
// here.
181+
/// Registers a callback to be called upon completion of this future. If the future has already
182+
/// completed, the callback will be called immediately.
183+
#[cfg(c_bindings)]
184+
pub fn register_callback_fn<F: 'static + FutureCallback>(&self, callback: F) {
185+
self.register_callback(Box::new(callback));
186+
}
175187
}
176188

177189
mod std_future {

0 commit comments

Comments
 (0)