-
Notifications
You must be signed in to change notification settings - Fork 668
Description
FutureObj requires a static vtable in the form of trait UnsafeFutureObj, this blocks being able to provide a conversion from Box<dyn Future<Output = ()>> to FutureObj<'static, ()> which would be useful for more optimized spawning.
I think one way to handle this would be to change FutureObj to directly contain a fat-pointer for the future + a function pointer for how to drop it (which can be statically determined by the concrete type containing the dyn Future when it's being converted to the FutureObj). That should be the same size as the existing implementation as the current poll_fn pointer is being replaced with the vtable pointer in the dyn Future. I guess it will require one more pointer lookup to find the poll_fn pointer in the vtable though...
pub struct LocalFutureObj<'a, T> {
future: *mut dyn Future<Output = T>,
drop_fn: unsafe fn(*mut dyn Future<Output = T>),
_marker: PhantomData<&'a ()>,
}