Description
This is a proposal for the next major release of futures-core.
(I will open issues for other crates later. They are probably 0.4 instead of 1.0.)
About
I propose to further reduce the APIs of futures-core and only provide what is really stable.
This makes futures-core a shim crate that provides future/task-related APIs of the standard library.
Eventually (maybe after core::stream::Stream
stabilized), only crates that need compatibility with older compilers will depend on futures-core, and other crates will not need to depend on futures-core.
APIs provided by this crate
The following two kinds of APIs are provided:
- APIs already stable in the standard library:
- In versions where it is stable, re-export from the standard library
- In versions where it doesn't exist in the standard library or isn't stable yet, futures-core defines & provides the same (use build-script to detect it).
This allows you to use items that are only available in the latest rustc, even if you are using an older version of rustc.
- APIs not yet stable in the standard library:
- If we know what (definition of items) will be added to the standard library, we can define and provide the same until it stabilizes.
- However, basically do not add at this stage.
Stream
trait andready!
macro are probably the only exceptions to this.
- Once stable, we can re-export with later versions (use build-script to detect it).
Other APIs are provided by individual futures-*
crate.
MSRV
APIs of this crate is really small, so it would be nice to be able to pin it to one of the following:
- Rust 1.36 that future/task-api stabilized.
- Rust 1.39 that async-await stabilized.
Every time the MSRV is increased, a new minor version is released.
Changes
Here is a list of proposed actual changes:
-
FusedFuture
,FusedStream
.- Remove. See futures-core 1.0 release #2207 (comment), select! without FusedFuture #1989, FusedFuture - should this really be a separate trait? #1894, and Bug in impl FusedFuture for futures::future::Map #2213 for main reasons.
- Uses of them in
select!
macro is replaced with the way suggested in select! without FusedFuture #1989.
- Type aliases (
BoxFuture
,LocalBoxFuture
,BoxStream
,LocalBoxStream
); pending in Move type/trait aliases to futures-util #2344- Move to
futures-util
. - They are just type aliases of
Pin<Box>
ed future/stream.
- Move to
- Trait aliases (
TryFuture
,TryStream
); pending in Move type/trait aliases to futures-util #2344- Move to
futures-util
. - They are just trait aliases of future/stream that return
Result
, but the real trait aliases are not yet stable, so they have some limitations. See doc: calling TryStreamExt methods on !Unpin values #2200 for one of the limitations.
- Move to
-
Stream
trait- Once the std
Stream
trait is stable,futures_core::Stream
is replaced with re-export from the standard library. (In the version that has stable std Stream, std Stream and futures_core::Stream is the same trait.)
* Addnext
method fromStreamExt
.- This may depend on the decisions of @rust-lang/wg-async-foundations or other teams. (As much as possible, I'd like to avoid the situation where the API of
Stream
changes after futures-core 1.0 is released.)
- This may depend on the decisions of @rust-lang/wg-async-foundations or other teams. (As much as possible, I'd like to avoid the situation where the API of
- Do not add other methods from
StreamExt
/TryStreamExt
. There is no general agreement on those APIs. Especialy, async closure vs normal closure.
- Once the std
-
ready!
macro- as-is
- This is still unstable in the standard library, but I don't think the API itself will change.
- The standard library's
ready!
macro maybecore::task::ready!
instead ofcore::ready!
, butfutures-core
expose this at top-revel.
Because:- To do the same requires an unstable feature.
- Unlike the standard library,
futures-core
provides only future/task-related items.
-
Wake
trait- Currently named as
ArcWake
, and defined infutures-task
. - Once
core::task::Wake
trait stable, re-export/define infutures-core
. From
-impl may not be available in the old version, so provide conversion utilities (waker
,waker_ref
) infutures-task
orfutures-util
.
- Currently named as
- Other utilities in
std::{future, task, stream}
- Once stable, re-exported/defined in
futures-core
. - And re-exported in
futures-util
. (Be careful with minimal-versions to avoid compile failure.)
- Once stable, re-exported/defined in
EDIT1: Clarified futures_core::Stream
changes when std Stream
is stable. (originally only described in "about" section's "APIs not yet stable in the standard library")
cc @cramertj @Nemo157 @seanmonstar
FYI @rust-lang/wg-async-foundations