Closed
Description
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:
- Passing around owned dynamically typed futures/streams. This can be replaced with use of the aliases below.
- Spawning futures via
Spawn::spawn_obj
. Rather than using this directly most users can useSpawnExt::spawn
instead to automatically convert the future into aFutureObj
(the only exception I know of isno_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
Labels
No labels