From 6cd308384340295add8c70a200474c52f8438e32 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 4 Dec 2019 16:39:38 -0800 Subject: [PATCH] feat(lib): rename `unstable-stream` feature to `stream` and enable by default Closes #2034 --- .travis.yml | 6 +++--- Cargo.toml | 21 +++++++++++---------- src/body/body.rs | 30 +++++++++++++++--------------- src/lib.rs | 5 +---- src/server/accept.rs | 8 ++++---- tests/server.rs | 6 +++--- 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef167ece2d..b9c80a4fa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,11 @@ matrix: fast_finish: true include: - rust: nightly - env: FEATURES="--no-default-features --features runtime,unstable-stream,nightly" + env: FEATURES="--no-default-features --features runtime,stream,nightly" - rust: beta - env: FEATURES="--no-default-features --features runtime,unstable-stream,__internal_happy_eyeballs_tests" + env: FEATURES="--no-default-features --features runtime,stream,__internal_happy_eyeballs_tests" #- rust: stable - # env: FEATURES="--no-default-features --features runtime,unstable-stream,__internal_happy_eyeballs_tests" + # env: FEATURES="--no-default-features --features runtime,stream,__internal_happy_eyeballs_tests" - rust: beta #stable env: FEATURES="--no-default-features" # Minimum Supported Rust Version diff --git a/Cargo.toml b/Cargo.toml index 456e005fba..38e8c67af0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ url = "1.0" default = [ "__internal_flaky_tests", "runtime", + "stream", ] runtime = [ "tcp", @@ -69,8 +70,8 @@ tcp = [ "tokio/time", ] -# unstable features -unstable-stream = [] +# `impl Stream` for things +stream = [] # internal features used in CI nightly = [] @@ -80,7 +81,7 @@ __internal_happy_eyeballs_tests = [] [package.metadata.docs.rs] features = [ "runtime", - "unstable-stream", + "stream", ] [profile.release] @@ -99,12 +100,12 @@ required-features = ["runtime"] [[example]] name = "client_json" path = "examples/client_json.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[example]] name = "echo" path = "examples/echo.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[example]] name = "hello" @@ -119,7 +120,7 @@ required-features = ["runtime"] [[example]] name = "params" path = "examples/params.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[example]] name = "proxy" @@ -160,7 +161,7 @@ required-features = ["runtime"] [[example]] name = "web_api" path = "examples/web_api.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[bench]] @@ -181,18 +182,18 @@ required-features = ["runtime"] [[bench]] name = "server" path = "benches/server.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[test]] name = "client" path = "tests/client.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[test]] name = "integration" path = "tests/integration.rs" -required-features = ["runtime", "unstable-stream"] +required-features = ["runtime", "stream"] [[test]] name = "server" diff --git a/src/body/body.rs b/src/body/body.rs index beaa942bec..7e49a1dd51 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -1,12 +1,12 @@ use std::borrow::Cow; -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] use std::error::Error as StdError; use std::fmt; use bytes::Bytes; use futures_core::Stream; // for mpsc::Receiver use futures_channel::{mpsc, oneshot}; -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] use futures_util::TryStreamExt; use http_body::{SizeHint, Body as HttpBody}; use http::HeaderMap; @@ -43,7 +43,7 @@ enum Kind { // while a borrow of a `Request` exists. // // See https://github.com/rust-lang/rust/issues/57017 - #[cfg(feature = "unstable-stream")] + #[cfg(feature = "stream")] Wrapped(Pin>> + Send + Sync>>), } @@ -142,11 +142,11 @@ impl Body { /// # } /// ``` /// - /// # Unstable + /// # Optional /// - /// This function requires enabling the `unstable-stream` feature in your + /// This function requires enabling the `stream` feature in your /// `Cargo.toml`. - #[cfg(feature = "unstable-stream")] + #[cfg(feature = "stream")] pub fn wrap_stream(stream: S) -> Body where S: Stream> + Send + Sync + 'static, @@ -280,7 +280,7 @@ impl Body { None => Poll::Ready(None), }, - #[cfg(feature = "unstable-stream")] + #[cfg(feature = "stream")] Kind::Wrapped(ref mut s) => { match ready!(s.as_mut().poll_next(cx)) { Some(res) => Poll::Ready(Some(res.map_err(crate::Error::new_body))), @@ -330,7 +330,7 @@ impl HttpBody for Body { Kind::Once(ref val) => val.is_none(), Kind::Chan { content_length, .. } => content_length == Some(0), Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(), - #[cfg(feature = "unstable-stream")] + #[cfg(feature = "stream")] Kind::Wrapped(..) => false, } } @@ -345,7 +345,7 @@ impl HttpBody for Body { Kind::Once(None) => { SizeHint::default() }, - #[cfg(feature = "unstable-stream")] + #[cfg(feature = "stream")] Kind::Wrapped(..) => SizeHint::default(), Kind::Chan { content_length, .. } | Kind::H2 { content_length, .. } => { let mut hint = SizeHint::default(); @@ -380,11 +380,11 @@ impl fmt::Debug for Body { } } -/// # Unstable +/// # Optional /// -/// This function requires enabling the `unstable-stream` feature in your +/// This function requires enabling the `stream` feature in your /// `Cargo.toml`. -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] impl Stream for Body { type Item = crate::Result; @@ -394,11 +394,11 @@ impl Stream for Body { } -/// # Unstable +/// # Optional /// -/// This function requires enabling the `unstable-stream` feature in your +/// This function requires enabling the `stream` feature in your /// `Cargo.toml`. -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] impl From>> + Send + Sync>> for Body diff --git a/src/lib.rs b/src/lib.rs index 6c941ed4ff..a86bdb45ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,10 +27,7 @@ //! executor. //! - `tcp` (*enabled by default*): Enables convenient implementations over //! TCP (using tokio). -//! - `unstable-stream` (*unstable*): Provides `futures::Stream` capabilities. -//! -//! Due to the `Stream` trait not being stable, this feature is also -//! unstable. It does not follow normal semver. +//! - `stream` (*enabled by default*): Provides `futures::Stream` capabilities. #[doc(hidden)] pub use http; #[macro_use] extern crate log; diff --git a/src/server/accept.rs b/src/server/accept.rs index 46a36a2756..b78220ceae 100644 --- a/src/server/accept.rs +++ b/src/server/accept.rs @@ -6,7 +6,7 @@ //! connections. //! - Utilities like `poll_fn` to ease creating a custom `Accept`. -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] use futures_core::Stream; use crate::common::{Pin, task::{self, Poll}}; @@ -68,11 +68,11 @@ where /// Adapt a `Stream` of incoming connections into an `Accept`. /// -/// # Unstable +/// # Optional /// -/// This function requires enabling the `unstable-stream` feature in your +/// This function requires enabling the `stream` feature in your /// `Cargo.toml`. -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] pub fn from_stream(stream: S) -> impl Accept where S: Stream>, diff --git a/tests/server.rs b/tests/server.rs index 02e3ccf7c8..5652ce4618 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -15,7 +15,7 @@ use std::time::Duration; use futures_channel::oneshot; use futures_util::future::{self, Either, FutureExt, TryFutureExt}; -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] use futures_util::stream::StreamExt as _; use http::header::{HeaderName, HeaderValue}; use tokio::net::{TcpListener, TcpStream as TkTcpStream}; @@ -1383,7 +1383,7 @@ async fn max_buf_size() { .expect_err("should TooLarge error"); } -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] #[test] fn streaming_body() { let _ = pretty_env_logger::try_init(); @@ -1497,7 +1497,7 @@ async fn http2_service_error_sends_reset_reason() { assert_eq!(h2_err.reason(), Some(h2::Reason::INADEQUATE_SECURITY)); } -#[cfg(feature = "unstable-stream")] +#[cfg(feature = "stream")] #[test] fn http2_body_user_error_sends_reset_reason() { use std::error::Error;