diff --git a/Cargo.toml b/Cargo.toml index 0f6e3149..0ac4201d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,7 +70,7 @@ runtime = [ ] # unstable features -stream = [] +unstable-stream = [] # internal features used in CI nightly = [] @@ -80,7 +80,7 @@ __internal_happy_eyeballs_tests = [] [package.metadata.docs.rs] features = [ "runtime", - "stream", + "unstable-stream", ] [profile.release] @@ -99,12 +99,12 @@ required-features = ["runtime"] [[example]] name = "client_json" path = "examples/client_json.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[example]] name = "echo" path = "examples/echo.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[example]] name = "hello" @@ -119,7 +119,7 @@ required-features = ["runtime"] [[example]] name = "params" path = "examples/params.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[example]] name = "proxy" @@ -160,7 +160,7 @@ required-features = ["runtime"] [[example]] name = "web_api" path = "examples/web_api.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[bench]] @@ -176,20 +176,20 @@ required-features = ["runtime"] [[bench]] name = "server" path = "benches/server.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[test]] name = "client" path = "tests/client.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[test]] name = "integration" path = "tests/integration.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] [[test]] name = "server" path = "tests/server.rs" -required-features = ["runtime", "stream"] +required-features = ["runtime", "unstable-stream"] diff --git a/src/body/body.rs b/src/body/body.rs index 3562bf8c..fda86915 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -1,14 +1,12 @@ use std::borrow::Cow; -#[cfg(feature = "stream")] +#[cfg(feature = "unstable-stream")] use std::error::Error as StdError; use std::fmt; use bytes::Bytes; use futures_core::Stream; // for mpsc::Receiver -#[cfg(feature = "stream")] -use futures_core::TryStream; use futures_channel::{mpsc, oneshot}; -#[cfg(feature = "stream")] +#[cfg(feature = "unstable-stream")] use futures_util::TryStreamExt; use http_body::{SizeHint, Body as HttpBody}; use http::HeaderMap; @@ -45,7 +43,7 @@ enum Kind { // while a borrow of a `Request` exists. // // See https://github.com/rust-lang/rust/issues/57017 - #[cfg(feature = "stream")] + #[cfg(feature = "unstable-stream")] Wrapped(Pin>> + Send + Sync>>), } @@ -146,16 +144,16 @@ impl Body { /// /// # Unstable /// - /// This function requires enabling the unstable `stream` feature in your + /// This function requires enabling the `unstable-stream` feature in your /// `Cargo.toml`. - #[cfg(feature = "stream")] - pub fn wrap_stream(stream: S) -> Body + #[cfg(feature = "unstable-stream")] + pub fn wrap_stream(stream: S) -> Body where - S: TryStream + Send + Sync + 'static, - S::Error: Into>, - Chunk: From, + S: Stream> + Send + Sync + 'static, + O: Into + 'static, + E: Into> + 'static, { - let mapped = stream.map_ok(Chunk::from).map_err(Into::into); + let mapped = stream.map_ok(Into::into).map_err(Into::into); Body::new(Kind::Wrapped(Box::pin(mapped))) } @@ -287,7 +285,7 @@ impl Body { None => Poll::Ready(None), }, - #[cfg(feature = "stream")] + #[cfg(feature = "unstable-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))), @@ -337,7 +335,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 = "stream")] + #[cfg(feature = "unstable-stream")] Kind::Wrapped(..) => false, } } @@ -352,7 +350,7 @@ impl HttpBody for Body { Kind::Once(None) => { SizeHint::default() }, - #[cfg(feature = "stream")] + #[cfg(feature = "unstable-stream")] Kind::Wrapped(..) => SizeHint::default(), Kind::Chan { content_length, .. } | Kind::H2 { content_length, .. } => { let mut hint = SizeHint::default(); @@ -387,7 +385,11 @@ impl fmt::Debug for Body { } } -#[cfg(feature = "stream")] +/// # Unstable +/// +/// This function requires enabling the `unstable-stream` feature in your +/// `Cargo.toml`. +#[cfg(feature = "unstable-stream")] impl Stream for Body { type Item = crate::Result; @@ -397,7 +399,11 @@ impl Stream for Body { } -#[cfg(feature = "stream")] +/// # Unstable +/// +/// This function requires enabling the `unstable-stream` feature in your +/// `Cargo.toml`. +#[cfg(feature = "unstable-stream")] impl From>> + Send + Sync>> for Body diff --git a/src/lib.rs b/src/lib.rs index 4ae36ae2..e30c1309 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,10 +22,13 @@ //! //! The following optional features are available: //! -//! - `runtime` (*enabled by default*): Enables convenient integration with +//! - `runtime` (*enabled by default*): Enables convenient integration with //! `tokio`, providing connectors and acceptors for TCP, and a default //! executor. -//! - `stream` (*unstable*): Provides `futures::Stream` capabilities. +//! - `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. #[doc(hidden)] pub use http; #[macro_use] extern crate log; diff --git a/src/server/accept.rs b/src/server/accept.rs index 9e1de03c..46a36a27 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 = "stream")] +#[cfg(feature = "unstable-stream")] use futures_core::Stream; use crate::common::{Pin, task::{self, Poll}}; @@ -70,9 +70,9 @@ where /// /// # Unstable /// -/// This function requires enabling the unstable `stream` feature in your +/// This function requires enabling the `unstable-stream` feature in your /// `Cargo.toml`. -#[cfg(feature = "stream")] +#[cfg(feature = "unstable-stream")] pub fn from_stream(stream: S) -> impl Accept where S: Stream>,