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
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"]

View File

@@ -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<Body>` exists.
//
// 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>>),
}
@@ -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<S>(stream: S) -> Body
#[cfg(feature = "unstable-stream")]
pub fn wrap_stream<S, O, E>(stream: S) -> Body
where
S: TryStream + Send + Sync + 'static,
S::Error: Into<Box<dyn StdError + Send + Sync>>,
Chunk: From<S::Ok>,
S: Stream<Item = Result<O, E>> + Send + Sync + 'static,
O: Into<Chunk> + 'static,
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)))
}
@@ -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<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
From<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>
for Body

View File

@@ -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;

View File

@@ -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<S, IO, E>(stream: S) -> impl Accept<Conn = IO, Error = E>
where
S: Stream<Item = Result<IO, E>>,