Skip to content

FutureObj doesn't support ?Sized types #1535

@Nemo157

Description

@Nemo157

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 ()>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions