From ffcb6f9a8018abfeed7f0e0b2afe88e22975962f Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Mon, 11 Jan 2021 20:17:19 -0500 Subject: [PATCH] Discontinue support for futures 0.1 --- .cirrus.yml | 6 - Cargo.toml | 6 +- compatibility-tests/futures-0.1/Cargo.toml | 9 - compatibility-tests/futures-0.1/src/lib.rs | 72 -------- src/futures01/future.rs | 182 --------------------- src/futures01/mod.rs | 16 -- src/futures01/stream.rs | 175 -------------------- src/guide/feature_flags.md | 12 -- src/lib.rs | 3 - 9 files changed, 1 insertion(+), 480 deletions(-) delete mode 100644 compatibility-tests/futures-0.1/Cargo.toml delete mode 100644 compatibility-tests/futures-0.1/src/lib.rs delete mode 100644 src/futures01/future.rs delete mode 100644 src/futures01/mod.rs delete mode 100644 src/futures01/stream.rs diff --git a/.cirrus.yml b/.cirrus.yml index 8e3649fd..2a4bd2ce 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -20,8 +20,6 @@ stable_test_task: - cargo test --manifest-path compatibility-tests/backtrace-shim/Cargo.toml backtraces_impl_backtrace_crate_test_script: - cargo test --manifest-path compatibility-tests/backtraces-impl-backtrace-crate/Cargo.toml - futures_0.1_test_script: - - cargo test --manifest-path compatibility-tests/futures-0.1/Cargo.toml context_selectors_have_documentation_test_script: - cargo test --manifest-path compatibility-tests/context-selectors-have-documentation/Cargo.toml renamed_import_test_script: @@ -60,8 +58,6 @@ doc_test_task: - cargo +nightly doc --features=backtraces-impl-backtrace-crate unstable_backtraces_impl_std_docs_script: - cargo +nightly doc --features=unstable-backtraces-impl-std - futures_01_docs_script: - - cargo +nightly doc --features=futures-01 futures_docs_script: - cargo +nightly doc --features=futures before_cache_script: rm -rf $CARGO_HOME/registry/index @@ -86,8 +82,6 @@ doc_tests_task: # # unstable_backtraces_impl_std_doctests_script: # - cargo +nightly test --doc --features=unstable-backtraces-impl-std - futures_01_doctests_script: - - cargo +nightly test --doc --features=futures-01 futures_doctests_script: - cargo +nightly test --doc --features=futures,internal-dev-dependencies before_cache_script: rm -rf $CARGO_HOME/registry/index diff --git a/Cargo.toml b/Cargo.toml index c3cc86ba..8ff30261 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ exclude = [ [package.metadata.docs.rs] # The backtraces-impl-* features are incompatible with each other -features = [ "std", "backtraces", "futures-01", "futures", "guide" ] +features = [ "std", "backtraces", "futures", "guide" ] [features] default = ["std", "guide"] @@ -40,9 +40,6 @@ backtraces-impl-backtrace-crate = ["backtraces"] # implement `std::error::Error::backtrace` unstable-backtraces-impl-std = ["backtraces", "snafu-derive/unstable-backtraces-impl-std"] -# Add extension traits for the futures 0.1 crate -futures-01 = ["futures-01-crate"] - # The standard library's implementation of futures futures = ["futures-core-crate", "pin-project"] @@ -62,7 +59,6 @@ exclude = ["compatibility-tests"] snafu-derive = { path = "snafu-derive", version = "0.6.10" } doc-comment = { version = "0.3.1", default-features = false } backtrace = { version = "0.3.0", optional = true } -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 = "1.0", optional = true, default-features = false } diff --git a/compatibility-tests/futures-0.1/Cargo.toml b/compatibility-tests/futures-0.1/Cargo.toml deleted file mode 100644 index ecca60a3..00000000 --- a/compatibility-tests/futures-0.1/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "futures_compat" -version = "0.1.0" -authors = ["Jake Goulding "] -edition = "2018" - -[dependencies] -snafu = { path = "../..", features = ["futures-01"] } -futures = "0.1.27" diff --git a/compatibility-tests/futures-0.1/src/lib.rs b/compatibility-tests/futures-0.1/src/lib.rs deleted file mode 100644 index c13a933d..00000000 --- a/compatibility-tests/futures-0.1/src/lib.rs +++ /dev/null @@ -1,72 +0,0 @@ -#![cfg(test)] - -mod api { - use futures::{future, stream, Future, Stream}; - use snafu::Snafu; - - #[derive(Debug, Snafu)] - pub enum Error { - InvalidUrl { url: String }, - } - - pub fn fetch_page(url: &str) -> impl Future { - future::result(InvalidUrl { url }.fail()) - } - - pub fn keep_fetching_page<'u>(url: &'u str) -> impl Stream + 'u { - stream::repeat::<_, ()>(()).then(move |_| fetch_page(url)) - } -} - -use futures::{future, Future, Stream}; -use snafu::{ - futures01::{future::FutureExt as _, stream::StreamExt as _}, - Snafu, -}; - -#[derive(Debug, Snafu)] -enum Error { - UnableToLoadAppleStock { source: api::Error }, - UnableToLoadGoogleStock { source: api::Error, name: String }, -} - -// Can be used as a `Future` combinator -fn load_stock_data_concurrent() -> impl Future { - let apple = api::fetch_page("apple").context(UnableToLoadAppleStock); - let google = api::fetch_page("google").with_context(|| UnableToLoadGoogleStock { - name: String::from("concurrent"), - }); - - apple - .join(google) - .map(|(apple, google)| format!("{}+{}", apple, google)) -} - -// Can be used as a `Stream` combinator -fn load_stock_data_series() -> impl Future { - let apple = api::keep_fetching_page("apple").context(UnableToLoadAppleStock); - let google = api::keep_fetching_page("google").with_context(|| UnableToLoadGoogleStock { - name: String::from("stream"), - }); - - apple - .zip(google) - .take(10) - .fold(String::new(), |mut acc, (a, g)| { - use std::fmt::Write; - writeln!(&mut acc, "{}+{}", a, g).expect("Could not format"); - future::ok(acc) - }) -} - -#[test] -fn implements_error() { - fn check() {} - check::(); - - let b = load_stock_data_concurrent().wait(); - b.unwrap_err(); - - let c = load_stock_data_series().wait(); - c.unwrap_err(); -} diff --git a/src/futures01/future.rs b/src/futures01/future.rs deleted file mode 100644 index cd006bcc..00000000 --- a/src/futures01/future.rs +++ /dev/null @@ -1,182 +0,0 @@ -//! Additions to the Futures 0.1 [`Future`] trait. -//! -//! [`Future`]: futures_01_crate::Future - -use crate::{Error, ErrorCompat, IntoError}; -use core::marker::PhantomData; -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`]: futures_01_crate::Future] - /// - /// ```rust - /// # use futures_01_crate as futures; - /// use futures::Future; - /// # use futures::future; - /// use snafu::{futures01::FutureExt, Snafu}; - /// - /// #[derive(Debug, Snafu)] - /// enum Error { - /// Authenticating { - /// user_name: String, - /// user_id: i32, - /// source: ApiError, - /// }, - /// } - /// - /// fn example() -> impl Future { - /// another_function().context(Authenticating { - /// user_name: "admin", - /// user_id: 42, - /// }) - /// } - /// - /// # type ApiError = Box; - /// fn another_function() -> impl Future { - /// /* ... */ - /// # future::ok(42) - /// } - /// ``` - /// - /// Note that the context selector will call [`Into::into`] on - /// each field, so the types are not required to exactly match. - fn context(self, context: C) -> Context - where - C: IntoError, - E: Error + ErrorCompat; - - /// Extend a [`Future`]'s error with lazily-generated context-sensitive - /// information. - /// - /// [`Future`]: futures_01_crate::Future] - /// - /// ```rust - /// # use futures_01_crate as futures; - /// use futures::Future; - /// # use futures::future; - /// use snafu::{futures01::FutureExt, Snafu}; - /// - /// #[derive(Debug, Snafu)] - /// enum Error { - /// Authenticating { - /// user_name: String, - /// user_id: i32, - /// source: ApiError, - /// }, - /// } - /// - /// fn example() -> impl Future { - /// another_function().with_context(|| Authenticating { - /// user_name: "admin".to_string(), - /// user_id: 42, - /// }) - /// } - /// - /// # type ApiError = std::io::Error; - /// fn another_function() -> impl Future { - /// /* ... */ - /// # future::ok(42) - /// } - /// ``` - /// - /// Note that this *may not* be needed in many cases because the - /// context selector will call [`Into::into`] on each field. - fn with_context(self, context: F) -> WithContext - where - F: FnOnce() -> C, - C: IntoError, - E: Error + ErrorCompat; -} - -impl FutureExt for Fut -where - Fut: Future, -{ - fn context(self, context: C) -> Context - where - C: IntoError, - E: Error + ErrorCompat, - { - Context { - future: self, - context: Some(context), - _e: PhantomData, - } - } - - fn with_context(self, context: F) -> WithContext - where - F: FnOnce() -> C, - C: IntoError, - E: Error + ErrorCompat, - { - WithContext { - future: self, - context: Some(context), - _e: PhantomData, - } - } -} - -/// Future for the [`context`](FutureExt::context) combinator. -/// -/// See the [`FutureExt::context`] method for more details. -pub struct Context { - future: Fut, - context: Option, - _e: PhantomData, -} - -impl Future for Context -where - Fut: Future, - C: IntoError, - E: Error + ErrorCompat, -{ - type Item = Fut::Item; - type Error = E; - - fn poll(&mut self) -> Result, Self::Error> { - self.future.poll().map_err(|error| { - self.context - .take() - .expect("cannot poll Context after it has resolved") - .into_error(error) - }) - } -} - -/// Future for the [`with_context`](FutureExt::with_context) combinator. -/// -/// See the [`FutureExt::with_context`] method for more details. -pub struct WithContext { - future: Fut, - context: Option, - _e: PhantomData, -} - -impl Future for WithContext -where - Fut: Future, - F: FnOnce() -> C, - C: IntoError, - E: Error + ErrorCompat, -{ - type Item = Fut::Item; - type Error = E; - - fn poll(&mut self) -> Result, Self::Error> { - self.future.poll().map_err(|error| { - let context = self - .context - .take() - .expect("cannot poll WithContext after it has resolved"); - - context().into_error(error) - }) - } -} diff --git a/src/futures01/mod.rs b/src/futures01/mod.rs deleted file mode 100644 index d638baa9..00000000 --- a/src/futures01/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -//! Additions to the Futures 0.1 [`Future`] and [`Stream`] traits. -//! -//! This module is only available when the `futures-01` [feature -//! flag] is enabled. -//! -//! [`Future`]: futures_01_crate::Future -//! [`Stream`]: futures_01_crate::Stream -//! [feature flag]: crate::guide::feature_flags - -pub mod future; -pub mod stream; - -#[doc(inline)] -pub use self::future::FutureExt; -#[doc(inline)] -pub use self::stream::StreamExt; diff --git a/src/futures01/stream.rs b/src/futures01/stream.rs deleted file mode 100644 index 0f0db32b..00000000 --- a/src/futures01/stream.rs +++ /dev/null @@ -1,175 +0,0 @@ -//! Additions to the Futures 0.1 [`Stream`] trait. -//! -//! [`Stream`]: futures_01_crate::Stream - -use crate::{Error, ErrorCompat, IntoError}; -use core::marker::PhantomData; -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`]: futures_01_crate::Stream] - /// - /// ```rust - /// # use futures_01_crate as futures; - /// use futures::Stream; - /// # use futures::stream; - /// use snafu::{futures01::StreamExt, Snafu}; - /// - /// #[derive(Debug, Snafu)] - /// enum Error { - /// Authenticating { - /// user_name: String, - /// user_id: i32, - /// source: ApiError, - /// }, - /// } - /// - /// fn example() -> impl Stream { - /// stock_prices().context(Authenticating { - /// user_name: "admin", - /// user_id: 42, - /// }) - /// } - /// - /// # type ApiError = Box; - /// fn stock_prices() -> impl Stream { - /// /* ... */ - /// # stream::empty() - /// } - /// ``` - /// - /// Note that the context selector will call [`Into::into`] on - /// each field, so the types are not required to exactly match. - fn context(self, context: C) -> Context - where - C: IntoError + Clone, - E: Error + ErrorCompat; - - /// Extend a [`Stream`]'s error with lazily-generated context-sensitive - /// information. - /// - /// [`Stream`]: futures_01_crate::Stream] - /// - /// ```rust - /// # use futures_01_crate as futures; - /// use futures::Stream; - /// # use futures::stream; - /// use snafu::{futures01::StreamExt, Snafu}; - /// - /// #[derive(Debug, Snafu)] - /// enum Error { - /// Authenticating { - /// user_name: String, - /// user_id: i32, - /// source: ApiError, - /// }, - /// } - /// - /// fn example() -> impl Stream { - /// stock_prices().with_context(|| Authenticating { - /// user_name: "admin".to_string(), - /// user_id: 42, - /// }) - /// } - /// - /// # type ApiError = std::io::Error; - /// fn stock_prices() -> impl Stream { - /// /* ... */ - /// # stream::empty() - /// } - /// ``` - /// - /// Note that this *may not* be needed in many cases because the - /// context selector will call [`Into::into`] on each field. - fn with_context(self, context: F) -> WithContext - where - F: FnMut() -> C, - C: IntoError, - E: Error + ErrorCompat; -} - -impl StreamExt for St -where - St: Stream, -{ - fn context(self, context: C) -> Context - where - C: IntoError + Clone, - E: Error + ErrorCompat, - { - Context { - stream: self, - context, - _e: PhantomData, - } - } - - fn with_context(self, context: F) -> WithContext - where - F: FnMut() -> C, - C: IntoError, - E: Error + ErrorCompat, - { - WithContext { - stream: self, - context, - _e: PhantomData, - } - } -} - -/// Stream for the [`context`](StreamExt::context) combinator. -/// -/// See the [`StreamExt::context`] method for more details. -pub struct Context { - stream: St, - context: C, - _e: PhantomData, -} - -impl Stream for Context -where - St: Stream, - C: IntoError + Clone, - E: Error + ErrorCompat, -{ - type Item = St::Item; - type Error = E; - - fn poll(&mut self) -> Result>, Self::Error> { - self.stream - .poll() - .map_err(|error| self.context.clone().into_error(error)) - } -} - -/// Stream for the [`with_context`](StreamExt::with_context) combinator. -/// -/// See the [`StreamExt::with_context`] method for more details. -pub struct WithContext { - stream: St, - context: F, - _e: PhantomData, -} - -impl Stream for WithContext -where - St: Stream, - F: FnMut() -> C, - C: IntoError, - E: Error + ErrorCompat, -{ - type Item = St::Item; - type Error = E; - - fn poll(&mut self) -> Result>, Self::Error> { - self.stream.poll().map_err(|error| { - let context = &mut self.context; - context().into_error(error) - }) - } -} diff --git a/src/guide/feature_flags.md b/src/guide/feature_flags.md index 22036b3c..5762f301 100644 --- a/src/guide/feature_flags.md +++ b/src/guide/feature_flags.md @@ -10,7 +10,6 @@ cases: - [`backtraces-impl-backtrace-crate`](#backtraces-impl-backtrace-crate) - [`unstable-backtraces-impl-std`](#unstable-backtraces-impl-std) - [`futures`](#futures) -- [`futures-01`](#futures-01) [controlling compatibility]: super::guide::compatibility [feature flags]: https://doc.rust-lang.org/stable/cargo/reference/specifying-dependencies.html#choosing-features @@ -79,14 +78,3 @@ and streams returning `Result`s. [`futures::TryFutureExt`]: crate::futures::TryFutureExt [`futures::TryStreamExt`]: crate::futures::TryStreamExt - -## `futures-01` - -**default**: disabled - -When enabled, you can use the [`futures01::FutureExt`] and -[`futures01::StreamExt`] traits to add context methods to futures -and streams. - -[`futures01::FutureExt`]: crate::futures01::FutureExt -[`futures01::StreamExt`]: crate::futures01::StreamExt diff --git a/src/lib.rs b/src/lib.rs index 091a252c..b711cd7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,9 +110,6 @@ pub use backtrace::Backtrace; #[cfg(feature = "unstable-backtraces-impl-std")] pub use std::backtrace::Backtrace; -#[cfg(feature = "futures-01")] -pub mod futures01; - #[cfg(feature = "futures")] pub mod futures;