You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we like the deferred pattern and keep it we may want to align with
axevent where it is implemented like below:
```rust
struct Deferred {
func: Option<Box<dyn FnOnce()>>,
}
impl Drop for Deferred {
fn drop(&mut self) {
let func = self.func.take().unwrap();
func();
}
}
impl Deferred {
pub fn new<F>(func: F) -> Self
where
F: FnOnce() + 'static,
{
Self {
func: Some(Box::new(func)),
}
}
}
```
But I think I forgot to reason about the safety because now that I look
at it I think we need to take care that F is Send.
Another implementation that I experimented with is storing the callback
as `Option<Box<dyn Any>>` and using `ptr::addr_of_mut!` to get a
pointer for the FFI call. This feels nice because there is less
indirection but:
- It still doesn't capture the Send requirement.
- I'm not sure if moving the Box makes it ub[^1]
[^1]: rust-lang/rust#129090
0 commit comments