refactor(lib): rename 'stream' feature to 'unstable-stream'

This commit is contained in:
Sean McArthur
2019-09-11 16:02:00 -07:00
parent cea3589ef7
commit 2b0405c48c
4 changed files with 41 additions and 32 deletions

View File

@@ -70,7 +70,7 @@ runtime = [
] ]
# unstable features # unstable features
stream = [] unstable-stream = []
# internal features used in CI # internal features used in CI
nightly = [] nightly = []
@@ -80,7 +80,7 @@ __internal_happy_eyeballs_tests = []
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = [ features = [
"runtime", "runtime",
"stream", "unstable-stream",
] ]
[profile.release] [profile.release]
@@ -99,12 +99,12 @@ required-features = ["runtime"]
[[example]] [[example]]
name = "client_json" name = "client_json"
path = "examples/client_json.rs" path = "examples/client_json.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[example]] [[example]]
name = "echo" name = "echo"
path = "examples/echo.rs" path = "examples/echo.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[example]] [[example]]
name = "hello" name = "hello"
@@ -119,7 +119,7 @@ required-features = ["runtime"]
[[example]] [[example]]
name = "params" name = "params"
path = "examples/params.rs" path = "examples/params.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[example]] [[example]]
name = "proxy" name = "proxy"
@@ -160,7 +160,7 @@ required-features = ["runtime"]
[[example]] [[example]]
name = "web_api" name = "web_api"
path = "examples/web_api.rs" path = "examples/web_api.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[bench]] [[bench]]
@@ -176,20 +176,20 @@ required-features = ["runtime"]
[[bench]] [[bench]]
name = "server" name = "server"
path = "benches/server.rs" path = "benches/server.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[test]] [[test]]
name = "client" name = "client"
path = "tests/client.rs" path = "tests/client.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[test]] [[test]]
name = "integration" name = "integration"
path = "tests/integration.rs" path = "tests/integration.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]
[[test]] [[test]]
name = "server" name = "server"
path = "tests/server.rs" path = "tests/server.rs"
required-features = ["runtime", "stream"] required-features = ["runtime", "unstable-stream"]

View File

@@ -1,14 +1,12 @@
use std::borrow::Cow; use std::borrow::Cow;
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
use std::error::Error as StdError; use std::error::Error as StdError;
use std::fmt; use std::fmt;
use bytes::Bytes; use bytes::Bytes;
use futures_core::Stream; // for mpsc::Receiver use futures_core::Stream; // for mpsc::Receiver
#[cfg(feature = "stream")]
use futures_core::TryStream;
use futures_channel::{mpsc, oneshot}; use futures_channel::{mpsc, oneshot};
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
use futures_util::TryStreamExt; use futures_util::TryStreamExt;
use http_body::{SizeHint, Body as HttpBody}; use http_body::{SizeHint, Body as HttpBody};
use http::HeaderMap; use http::HeaderMap;
@@ -45,7 +43,7 @@ enum Kind {
// while a borrow of a `Request<Body>` exists. // while a borrow of a `Request<Body>` exists.
// //
// See https://github.com/rust-lang/rust/issues/57017 // See https://github.com/rust-lang/rust/issues/57017
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
Wrapped(Pin<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>), Wrapped(Pin<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>),
} }
@@ -146,16 +144,16 @@ impl Body {
/// ///
/// # Unstable /// # Unstable
/// ///
/// This function requires enabling the unstable `stream` feature in your /// This function requires enabling the `unstable-stream` feature in your
/// `Cargo.toml`. /// `Cargo.toml`.
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
pub fn wrap_stream<S>(stream: S) -> Body pub fn wrap_stream<S, O, E>(stream: S) -> Body
where where
S: TryStream + Send + Sync + 'static, S: Stream<Item = Result<O, E>> + Send + Sync + 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>, O: Into<Chunk> + 'static,
Chunk: From<S::Ok>, E: Into<Box<dyn StdError + Send + Sync>> + '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))) Body::new(Kind::Wrapped(Box::pin(mapped)))
} }
@@ -287,7 +285,7 @@ impl Body {
None => Poll::Ready(None), None => Poll::Ready(None),
}, },
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
Kind::Wrapped(ref mut s) => { Kind::Wrapped(ref mut s) => {
match ready!(s.as_mut().poll_next(cx)) { match ready!(s.as_mut().poll_next(cx)) {
Some(res) => Poll::Ready(Some(res.map_err(crate::Error::new_body))), 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::Once(ref val) => val.is_none(),
Kind::Chan { content_length, .. } => content_length == Some(0), Kind::Chan { content_length, .. } => content_length == Some(0),
Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(), Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(),
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
Kind::Wrapped(..) => false, Kind::Wrapped(..) => false,
} }
} }
@@ -352,7 +350,7 @@ impl HttpBody for Body {
Kind::Once(None) => { Kind::Once(None) => {
SizeHint::default() SizeHint::default()
}, },
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
Kind::Wrapped(..) => SizeHint::default(), Kind::Wrapped(..) => SizeHint::default(),
Kind::Chan { content_length, .. } | Kind::H2 { content_length, .. } => { Kind::Chan { content_length, .. } | Kind::H2 { content_length, .. } => {
let mut hint = SizeHint::default(); 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 { impl Stream for Body {
type Item = crate::Result<Chunk>; type Item = crate::Result<Chunk>;
@@ -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 impl
From<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>> From<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>
for Body for Body

View File

@@ -22,10 +22,13 @@
//! //!
//! The following optional features are available: //! 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 //! `tokio`, providing connectors and acceptors for TCP, and a default
//! executor. //! 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; #[doc(hidden)] pub use http;
#[macro_use] extern crate log; #[macro_use] extern crate log;

View File

@@ -6,7 +6,7 @@
//! connections. //! connections.
//! - Utilities like `poll_fn` to ease creating a custom `Accept`. //! - Utilities like `poll_fn` to ease creating a custom `Accept`.
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
use futures_core::Stream; use futures_core::Stream;
use crate::common::{Pin, task::{self, Poll}}; use crate::common::{Pin, task::{self, Poll}};
@@ -70,9 +70,9 @@ where
/// ///
/// # Unstable /// # Unstable
/// ///
/// This function requires enabling the unstable `stream` feature in your /// This function requires enabling the `unstable-stream` feature in your
/// `Cargo.toml`. /// `Cargo.toml`.
#[cfg(feature = "stream")] #[cfg(feature = "unstable-stream")]
pub fn from_stream<S, IO, E>(stream: S) -> impl Accept<Conn = IO, Error = E> pub fn from_stream<S, IO, E>(stream: S) -> impl Accept<Conn = IO, Error = E>
where where
S: Stream<Item = Result<IO, E>>, S: Stream<Item = Result<IO, E>>,