mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-12 19:36:45 +00:00
Merge #209
209: add feature guards for unstable features r=yoshuawuyts a=yoshuawuyts Makes sure unstable features aren't accidentally usable without their corresponding flags. Thanks! Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com> Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
This commit is contained in:
commit
91f002d12b
8 changed files with 39 additions and 14 deletions
|
@ -50,7 +50,7 @@ matrix:
|
||||||
rust: nightly
|
rust: nightly
|
||||||
os: linux
|
os: linux
|
||||||
script:
|
script:
|
||||||
- cargo doc --features docs
|
- cargo doc --features docs unstable
|
||||||
|
|
||||||
- name: book
|
- name: book
|
||||||
rust: nightly
|
rust: nightly
|
||||||
|
@ -64,4 +64,4 @@ matrix:
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cargo check --features unstable --all --benches --bins --examples --tests
|
- cargo check --features unstable --all --benches --bins --examples --tests
|
||||||
- cargo test --features unstable --all
|
- cargo test --all --doc --features unstable
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::task::{Context, Poll};
|
||||||
/// # Ok(()) }) }
|
/// # Ok(()) }) }
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
|
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
|
||||||
where
|
where
|
||||||
F: Future<Output = T>,
|
F: Future<Output = T>,
|
||||||
|
@ -69,6 +70,7 @@ impl<F: Future> Future for TimeoutFuture<F> {
|
||||||
|
|
||||||
/// An error returned when a future times out.
|
/// An error returned when a future times out.
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
pub struct TimeoutError {
|
pub struct TimeoutError {
|
||||||
_private: (),
|
_private: (),
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -42,20 +42,24 @@
|
||||||
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
|
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
|
||||||
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
||||||
|
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod future;
|
pub mod future;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod net;
|
pub mod net;
|
||||||
pub mod os;
|
pub mod os;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
mod result;
|
|
||||||
pub mod stream;
|
pub mod stream;
|
||||||
pub mod sync;
|
pub mod sync;
|
||||||
pub mod task;
|
pub mod task;
|
||||||
mod vec;
|
|
||||||
|
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
cfg_if! {
|
||||||
#[cfg(feature = "unstable")]
|
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
||||||
pub mod pin;
|
pub mod pin;
|
||||||
|
mod vec;
|
||||||
|
mod result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) mod utils;
|
pub(crate) mod utils;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use std::task::{Context, Poll};
|
||||||
///
|
///
|
||||||
/// [`Stream`]: trait.Stream.html
|
/// [`Stream`]: trait.Stream.html
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
pub trait DoubleEndedStream: Stream {
|
pub trait DoubleEndedStream: Stream {
|
||||||
/// Removes and returns an element from the end of the stream.
|
/// Removes and returns an element from the end of the stream.
|
||||||
///
|
///
|
||||||
|
|
|
@ -11,6 +11,7 @@ use std::pin::Pin;
|
||||||
///
|
///
|
||||||
/// [`IntoStream`]: trait.IntoStream.html
|
/// [`IntoStream`]: trait.IntoStream.html
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
pub trait FromStream<T: Send> {
|
pub trait FromStream<T: Send> {
|
||||||
/// Creates a value from a stream.
|
/// Creates a value from a stream.
|
||||||
///
|
///
|
||||||
|
|
|
@ -14,6 +14,7 @@ use futures_core::stream::Stream;
|
||||||
///
|
///
|
||||||
/// [`FromStream`]: trait.FromStream.html
|
/// [`FromStream`]: trait.FromStream.html
|
||||||
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
pub trait IntoStream {
|
pub trait IntoStream {
|
||||||
/// The type of the elements being iterated over.
|
/// The type of the elements being iterated over.
|
||||||
type Item;
|
type Item;
|
||||||
|
|
|
@ -21,18 +21,26 @@
|
||||||
//! # }) }
|
//! # }) }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
pub use double_ended_stream::DoubleEndedStream;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
pub use empty::{empty, Empty};
|
pub use empty::{empty, Empty};
|
||||||
pub use from_stream::FromStream;
|
|
||||||
pub use into_stream::IntoStream;
|
|
||||||
pub use once::{once, Once};
|
pub use once::{once, Once};
|
||||||
pub use repeat::{repeat, Repeat};
|
pub use repeat::{repeat, Repeat};
|
||||||
pub use stream::{Fuse, Scan, Stream, Take, Zip};
|
pub use stream::{Fuse, Scan, Stream, Take, Zip};
|
||||||
|
|
||||||
mod double_ended_stream;
|
|
||||||
mod empty;
|
mod empty;
|
||||||
mod from_stream;
|
|
||||||
mod into_stream;
|
|
||||||
mod once;
|
mod once;
|
||||||
mod repeat;
|
mod repeat;
|
||||||
mod stream;
|
mod stream;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
||||||
|
mod double_ended_stream;
|
||||||
|
mod from_stream;
|
||||||
|
mod into_stream;
|
||||||
|
|
||||||
|
pub use double_ended_stream::DoubleEndedStream;
|
||||||
|
pub use from_stream::FromStream;
|
||||||
|
pub use into_stream::IntoStream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ use min_by::MinByFuture;
|
||||||
use next::NextFuture;
|
use next::NextFuture;
|
||||||
use nth::NthFuture;
|
use nth::NthFuture;
|
||||||
|
|
||||||
use super::from_stream::FromStream;
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
@ -60,6 +59,12 @@ use std::task::{Context, Poll};
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(any(feature = "unstable", feature = "docs"))] {
|
||||||
|
use crate::stream::FromStream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "docs")] {
|
if #[cfg(feature = "docs")] {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -91,6 +96,7 @@ cfg_if! {
|
||||||
($a:lifetime, $o:ty) => (DynFuture<$a, $o>);
|
($a:lifetime, $o:ty) => (DynFuture<$a, $o>);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#[allow(unused_macros)]
|
||||||
macro_rules! dyn_ret {
|
macro_rules! dyn_ret {
|
||||||
($a:lifetime, $o:ty) => (Pin<Box<dyn core::future::Future<Output = $o> + Send + 'a>>)
|
($a:lifetime, $o:ty) => (Pin<Box<dyn core::future::Future<Output = $o> + Send + 'a>>)
|
||||||
}
|
}
|
||||||
|
@ -748,6 +754,8 @@ pub trait Stream {
|
||||||
///
|
///
|
||||||
/// [`stream`]: trait.Stream.html#tymethod.next
|
/// [`stream`]: trait.Stream.html#tymethod.next
|
||||||
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"]
|
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"]
|
||||||
|
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
|
||||||
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
||||||
fn collect<'a, B>(self) -> dyn_ret!('a, B)
|
fn collect<'a, B>(self) -> dyn_ret!('a, B)
|
||||||
where
|
where
|
||||||
Self: futures_core::stream::Stream + Sized + Send + 'a,
|
Self: futures_core::stream::Stream + Sized + Send + 'a,
|
||||||
|
|
Loading…
Reference in a new issue