Skip to content

Commit

Permalink
feat(lib): rename unstable-stream feature to stream and enable by…
Browse files Browse the repository at this point in the history
… default

Closes #2034
  • Loading branch information
seanmonstar committed Dec 5, 2019
1 parent aa66de4 commit 0b03b73
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ url = "1.0"
default = [
"__internal_flaky_tests",
"runtime",
"stream",
]
runtime = [
"tcp",
Expand All @@ -69,8 +70,8 @@ tcp = [
"tokio/time",
]

# unstable features
unstable-stream = []
# `impl Stream` for things
stream = []

# internal features used in CI
nightly = []
Expand All @@ -80,7 +81,7 @@ __internal_happy_eyeballs_tests = []
[package.metadata.docs.rs]
features = [
"runtime",
"unstable-stream",
"stream",
]

[profile.release]
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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]]
Expand All @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions src/body/body.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -43,7 +43,7 @@ enum Kind {
// while a borrow of a `Request<Body>` exists.
//
// See https://github.com/rust-lang/rust/issues/57017
#[cfg(feature = "unstable-stream")]
#[cfg(feature = "stream")]
Wrapped(Pin<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>),
}

Expand Down Expand Up @@ -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<S, O, E>(stream: S) -> Body
where
S: Stream<Item = Result<O, E>> + Send + Sync + 'static,
Expand Down Expand Up @@ -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))),
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -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();
Expand Down Expand Up @@ -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<Chunk>;

Expand All @@ -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<Box<dyn Stream<Item = Result<Chunk, Box<dyn StdError + Send + Sync>>> + Send + Sync>>
for Body
Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/server/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
Expand Down Expand Up @@ -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<S, IO, E>(stream: S) -> impl Accept<Conn = IO, Error = E>
where
S: Stream<Item = Result<IO, E>>,
Expand Down
6 changes: 3 additions & 3 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0b03b73

Please sign in to comment.