Skip to content

Remove StreamObj and soft-deprecate FutureObj #1352

Closed
@Nemo157

Description

@Nemo157

For some prior context see #1348

Now that futures and streams are object safe there should be no reason to use FutureObj/StreamObj directly. There are currently two reasons I know of to use these:

  1. Passing around owned dynamically typed futures/streams. This can be replaced with use of the aliases below.
  2. Spawning futures via Spawn::spawn_obj. Rather than using this directly most users can use SpawnExt::spawn instead to automatically convert the future into a FutureObj (the only exception I know of is no_std use).

(am I missing any other use cases? I admit I've personally never used FutureObj)

Proposed additions to futures:

type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
type BoxStream<'a, T> = Pin<Box<dyn Stream<Item = T> + Send + 'a>>;

Using SpawnExt::spawn for a BoxFuture<'static, ()> will cause a double indirection, this can be mitigated by either specialization (maybe, I don't know whether this is specializable) or an additional SpawnExt::spawn_box method that directly converts the boxed future into a FutureObj.

trait SpawnExt {
    fn spawn_box(&mut self, future: BoxFuture<'static, ()>) -> Result<(), SpawnError> { ... }
}

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