Skip to content

Commit

Permalink
Stabilize standard-library futures support
Browse files Browse the repository at this point in the history
Closes #115
  • Loading branch information
shepmaster committed Nov 7, 2019
1 parent 34d4379 commit 25d1c30
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 41 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ backtraces-impl-backtrace-crate = ["backtraces"]
unstable-backtraces-impl-std = ["backtraces", "snafu-derive/unstable-backtraces-impl-std"]

# Add extension traits for the futures 0.1 crate
"futures-01" = ["futures01"]
futures-01 = ["futures-01-crate"]

# The standard library's implementation of futures
"unstable-futures" = ["futures-core-preview", "pin-project"]
futures = ["futures-core-crate", "pin-project"]

# No public user should make use of this feature
# https://github.com/rust-lang/cargo/issues/1596
"internal-dev-dependencies" = ["futures-preview"]
"internal-dev-dependencies" = ["futures-crate"]

[workspace]
# The compatibility tests each set feature flags for the library and
Expand All @@ -58,7 +58,7 @@ exclude = ["compatibility-tests"]
snafu-derive = { path = "snafu-derive", version = "0.5.0" }
doc-comment = { version = "0.3.1", default-features = false }
backtrace = { version = "0.3.0", optional = true }
futures01 = { version = "0.1", optional = true, default-features = false }
futures-preview = { version = "0.3.0-alpha.16", optional = true, default-features = false }
futures-core-preview = { version = "0.3.0-alpha.16", optional = true, default-features = false }
futures-01-crate = { package = "futures", version = "0.1", optional = true, default-features = false }
futures-crate = { package = "futures", version = "0.3.0", optional = true, default-features = false }
futures-core-crate = { package = "futures-core", version = "0.3.0", optional = true, default-features = false }
pin-project = { version = "0.4", optional = true, default-features = false }
4 changes: 2 additions & 2 deletions compatibility-tests/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["Jake Goulding <jake.goulding@gmail.com>"]
edition = "2018"

[dependencies]
snafu = { path = "../..", features = ["unstable-futures"] }
futures-preview = "0.3.0-alpha.16"
snafu = { path = "../..", features = ["futures"] }
futures = "0.3.0"
2 changes: 1 addition & 1 deletion compatibility-tests/futures/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly
beta
8 changes: 4 additions & 4 deletions src/futures/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Additions to the [`TryFuture`] and [`TryStream`] traits.
//!
//! This module is only available when the `unstable-futures` [feature
//! flag] is enabled.
//! This module is only available when the `futures` [feature flag] is
//! enabled.
//!
//! [`TryFuture`]: futures_core::TryFuture
//! [`TryStream`]: futures_core::TryStream
//! [`TryFuture`]: futures_core_crate::TryFuture
//! [`TryStream`]: futures_core_crate::TryStream
//! [feature flag]: crate::guide::feature_flags
pub mod try_future;
Expand Down
6 changes: 4 additions & 2 deletions src/futures/try_future.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Additions to the [`TryFuture`] trait.
//!
//! [`TryFuture`]: futures_core::future::TryFuture
//! [`TryFuture`]: futures_core_crate::future::TryFuture
use crate::{Error, ErrorCompat, IntoError};
use core::{
Expand All @@ -9,7 +9,7 @@ use core::{
pin::Pin,
task::{Context as TaskContext, Poll},
};
use futures_core::future::TryFuture;
use futures_core_crate::future::TryFuture;
use pin_project::pin_project;

/// Additions to [`TryFuture`].
Expand All @@ -18,6 +18,7 @@ pub trait TryFutureExt: TryFuture + Sized {
/// information.
///
/// ```rust
/// # use futures_crate as futures;
/// use futures::future::TryFuture;
/// use snafu::{futures::TryFutureExt, Snafu};
///
Expand Down Expand Up @@ -55,6 +56,7 @@ pub trait TryFutureExt: TryFuture + Sized {
/// information.
///
/// ```rust
/// # use futures_crate as futures;
/// use futures::future::TryFuture;
/// use snafu::{futures::TryFutureExt, Snafu};
///
Expand Down
6 changes: 4 additions & 2 deletions src/futures/try_stream.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! Additions to the [`TryStream`] trait.
//!
//! [`TryStream`]: futures_core::TryStream
//! [`TryStream`]: futures_core_crate::TryStream
use crate::{Error, ErrorCompat, IntoError};
use core::{
marker::PhantomData,
pin::Pin,
task::{Context as TaskContext, Poll},
};
use futures_core::stream::{Stream, TryStream};
use futures_core_crate::stream::{Stream, TryStream};
use pin_project::pin_project;

/// Additions to [`TryStream`].
Expand All @@ -17,6 +17,7 @@ pub trait TryStreamExt: TryStream + Sized {
/// information.
///
/// ```rust
/// # use futures_crate as futures;
/// use futures::TryStream;
/// # use futures::stream;
/// use snafu::{futures::TryStreamExt, Snafu};
Expand Down Expand Up @@ -55,6 +56,7 @@ pub trait TryStreamExt: TryStream + Sized {
/// context-sensitive information.
///
/// ```rust
/// # use futures_crate as futures;
/// use futures::TryStream;
/// # use futures::stream;
/// use snafu::{futures::TryStreamExt, Snafu};
Expand Down
18 changes: 10 additions & 8 deletions src/futures01/future.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//! Additions to the Futures 0.1 [`Future`] trait.
//!
//! [`Future`]: futures01_crate::Future
//! [`Future`]: futures_01_crate::Future
use crate::{Error, ErrorCompat, IntoError};
use core::marker::PhantomData;
use futures01::{Async, Future};
use futures_01_crate::{Async, Future};

/// Additions to [`Future`].
pub trait FutureExt: Future + Sized {
/// Extend a [`Future`]'s error with additional context-sensitive
/// information.
///
/// [`Future`]: futures01::Future]
/// [`Future`]: futures_01_crate::Future]
///
/// ```rust
/// use futures01::Future;
/// # use futures01::future;
/// # use futures_01_crate as futures;
/// use futures::Future;
/// # use futures::future;
/// use snafu::{futures01::FutureExt, Snafu};
///
/// #[derive(Debug, Snafu)]
Expand Down Expand Up @@ -51,11 +52,12 @@ pub trait FutureExt: Future + Sized {
/// Extend a [`Future`]'s error with lazily-generated context-sensitive
/// information.
///
/// [`Future`]: futures01::Future]
/// [`Future`]: futures_01_crate::Future]
///
/// ```rust
/// use futures01::Future;
/// # use futures01::future;
/// # use futures_01_crate as futures;
/// use futures::Future;
/// # use futures::future;
/// use snafu::{futures01::FutureExt, Snafu};
///
/// #[derive(Debug, Snafu)]
Expand Down
4 changes: 2 additions & 2 deletions src/futures01/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! This module is only available when the `futures-01` [feature
//! flag] is enabled.
//!
//! [`Future`]: futures01_crate::Future
//! [`Stream`]: futures01_crate::Stream
//! [`Future`]: futures_01_crate::Future
//! [`Stream`]: futures_01_crate::Stream
//! [feature flag]: crate::guide::feature_flags
pub mod future;
Expand Down
18 changes: 10 additions & 8 deletions src/futures01/stream.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//! Additions to the Futures 0.1 [`Stream`] trait.
//!
//! [`Stream`]: futures01_crate::Stream
//! [`Stream`]: futures_01_crate::Stream
use crate::{Error, ErrorCompat, IntoError};
use core::marker::PhantomData;
use futures01::{Async, Stream};
use futures_01_crate::{Async, Stream};

/// Additions to [`Stream`].
pub trait StreamExt: Stream + Sized {
/// Extend a [`Stream`]'s error with additional context-sensitive
/// information.
///
/// [`Stream`]: futures01::Stream]
/// [`Stream`]: futures_01_crate::Stream]
///
/// ```rust
/// use futures01::Stream;
/// # use futures01::stream;
/// # use futures_01_crate as futures;
/// use futures::Stream;
/// # use futures::stream;
/// use snafu::{futures01::StreamExt, Snafu};
///
/// #[derive(Debug, Snafu)]
Expand Down Expand Up @@ -51,11 +52,12 @@ pub trait StreamExt: Stream + Sized {
/// Extend a [`Stream`]'s error with lazily-generated context-sensitive
/// information.
///
/// [`Stream`]: futures01::Stream]
/// [`Stream`]: futures_01_crate::Stream]
///
/// ```rust
/// use futures01::Stream;
/// # use futures01::stream;
/// # use futures_01_crate as futures;
/// use futures::Stream;
/// # use futures::stream;
/// use snafu::{futures01::StreamExt, Snafu};
///
/// #[derive(Debug, Snafu)]
Expand Down
6 changes: 2 additions & 4 deletions src/guide/feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ some point in the future, the standard library will have its own
backtrace type that SNAFU will use and this feature will conflict with
its use.

### `unstable-futures`
### `futures`

**default**: disabled

When enabled, you can use the [`futures::TryFutureExt`] and
[`futures::TryStreamExt`] traits to add context methods to futures
and streams returning `Result`s.

Note that this feature requires nightly Rust and may break at any
time. When the standard library implementation stabilizes, this
feature flag will be renamed and stabilized.
Note that this feature requires Rust 1.39.

[`futures::TryFutureExt`]: crate::futures::TryFutureExt
[`futures::TryStreamExt`]: crate::futures::TryStreamExt
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub use std::backtrace::Backtrace;
#[cfg(feature = "futures-01")]
pub mod futures01;

#[cfg(feature = "unstable-futures")]
#[cfg(feature = "futures")]
pub mod futures;

pub use snafu_derive::Snafu;
Expand Down
2 changes: 1 addition & 1 deletion src/no_std_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl_error![
];

// We can gate these together with std futures.
#[cfg(feature = "unstable-futures")]
#[cfg(feature = "futures")]
impl_error![
core::num::TryFromIntError, // 1.34
core::array::TryFromSliceError, // 1.34
Expand Down

0 comments on commit 25d1c30

Please sign in to comment.