Skip to content

Add "std" feature flag #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
7 commits merged into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
command: check
args: --features unstable --all --benches --bins --examples --tests

- name: check std only
uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --features std

- name: tests
uses: actions-rs/cargo@v1
with:
Expand Down
66 changes: 44 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,54 @@ features = ["docs"]
rustdoc-args = ["--cfg", "feature=\"docs\""]

[features]
default = []
docs = ["unstable", "attributes"]
unstable = ["broadcaster"]
attributes = ["async-attributes"]
default = [
"std",
"async-task",
"crossbeam-channel",
"crossbeam-deque",
"futures-timer",
"kv-log-macro",
"log",
"mio",
"mio-uds",
"num_cpus",
"pin-project-lite",
]
docs = ["unstable"]
unstable = ["default", "broadcaster"]
std = [
"async-macros",
"crossbeam-utils",
"futures-core",
"futures-io",
"memchr",
"once_cell",
"pin-project-lite",
"pin-utils",
"slab",
]

[dependencies]
async-attributes = { version = "1.1.0", optional = true }
async-macros = "1.0.0"
async-task = "1.0.0"
async-macros = { version = "1.0.0", optional = true }
async-task = { version = "1.0.0", optional = true }
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
crossbeam-channel = "0.3.9"
crossbeam-deque = "0.7.1"
crossbeam-utils = "0.6.6"
futures-core = "0.3.0"
futures-io = "0.3.0"
futures-timer = "1.0.2"
kv-log-macro = "1.0.4"
log = { version = "0.4.8", features = ["kv_unstable"] }
memchr = "2.2.1"
mio = "0.6.19"
mio-uds = "0.6.7"
num_cpus = "1.10.1"
once_cell = "1.2.0"
pin-project-lite = "0.1"
pin-utils = "0.1.0-alpha.4"
slab = "0.4.2"
crossbeam-channel = { version = "0.3.9", optional = true }
crossbeam-deque = { version = "0.7.1", optional = true }
crossbeam-utils = { version = "0.6.6", optional = true }
futures-core = { version = "0.3.0", optional = true }
futures-io = { version = "0.3.0", optional = true }
futures-timer = { version = "1.0.2", optional = true }
kv-log-macro = { version = "1.0.4", optional = true }
log = { version = "0.4.8", features = ["kv_unstable"], optional = true }
memchr = { version = "2.2.1", optional = true }
mio = { version = "0.6.19", optional = true }
mio-uds = { version = "0.6.7", optional = true }
num_cpus = { version = "1.10.1", optional = true }
once_cell = { version = "1.2.0", optional = true }
pin-project-lite = { version = "0.1", optional = true }
pin-utils = { version = "0.1.0-alpha.4", optional = true }
slab = { version = "0.4.2", optional = true }

[dev-dependencies]
femme = "1.2.0"
Expand Down
8 changes: 4 additions & 4 deletions src/future/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ extension_trait! {
/// dbg!(a.await);
/// # })
/// ```
#[cfg(all(feature = "default", feature = "unstable"))]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[cfg(any(feature = "unstable", feature = "docs"))]
fn delay(self, dur: Duration) -> impl Future<Output = Self::Output> [DelayFuture<Self>]
where
Self: Future + Sized
Expand All @@ -167,8 +167,8 @@ extension_trait! {
/// assert_eq!(future.await, 1);
/// # })
/// ```
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
#[cfg(any(feature = "unstable", feature = "docs"))]
fn flatten(self) -> impl Future<Output = <<Self as Future>::Output as IntoFuture>::Output> [FlattenFuture<Self, <<Self as Future>::Output as IntoFuture>::Future>]
where
Self: Future + Sized,
Expand Down Expand Up @@ -206,7 +206,7 @@ extension_trait! {
# });
```
"#]
#[cfg(any(feature = "unstable", feature = "docs"))]
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
fn race<F>(
self,
Expand Down Expand Up @@ -252,7 +252,7 @@ extension_trait! {
# Ok(()) }) }
```
"#]
#[cfg(any(feature = "unstable", feature = "docs"))]
#[cfg(feature = "unstable")]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
fn try_race<F: std::future::Future, T, E>(
self,
Expand Down
7 changes: 5 additions & 2 deletions src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ pub use future::Future;
pub use pending::pending;
pub use poll_fn::poll_fn;
pub use ready::ready;
pub use timeout::{timeout, TimeoutError};

pub(crate) mod future;
mod pending;
mod poll_fn;
mod ready;
mod timeout;

cfg_default! {
pub use timeout::{timeout, TimeoutError};
mod timeout;
}

cfg_unstable! {
pub use into_future::IntoFuture;
Expand Down
80 changes: 43 additions & 37 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,48 +269,54 @@
//! [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
//! [`.unwrap()`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap

#[doc(inline)]
pub use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Result, SeekFrom};
cfg_std! {
#[doc(inline)]
pub use std::io::{Error, ErrorKind, IoSlice, IoSliceMut, Result, SeekFrom};

pub use buf_read::{BufRead, Lines};
pub use buf_reader::BufReader;
pub use buf_writer::BufWriter;
pub use copy::copy;
pub use cursor::Cursor;
pub use empty::{empty, Empty};
pub use read::Read;
pub use repeat::{repeat, Repeat};
pub use seek::Seek;
pub use sink::{sink, Sink};
pub use stderr::{stderr, Stderr};
pub use stdin::{stdin, Stdin};
pub use stdout::{stdout, Stdout};
pub use timeout::timeout;
pub use write::Write;
pub use buf_read::{BufRead, Lines};
pub use buf_reader::BufReader;
pub use buf_writer::BufWriter;
pub use copy::copy;
pub use cursor::Cursor;
pub use empty::{empty, Empty};
pub use read::Read;
pub use repeat::{repeat, Repeat};
pub use seek::Seek;
pub use sink::{sink, Sink};
pub use write::Write;

// For use in the print macros.
#[doc(hidden)]
pub use stdio::{_eprint, _print};
pub mod prelude;

pub mod prelude;
pub(crate) mod buf_read;
pub(crate) mod read;
pub(crate) mod seek;
pub(crate) mod write;

pub(crate) mod buf_read;
pub(crate) mod read;
pub(crate) mod seek;
pub(crate) mod write;
mod buf_reader;
mod buf_writer;
mod copy;
mod cursor;
mod empty;
mod repeat;
mod sink;
}

cfg_default! {
// For use in the print macros.
#[doc(hidden)]
pub use stdio::{_eprint, _print};

mod buf_reader;
mod buf_writer;
mod copy;
mod cursor;
mod empty;
mod repeat;
mod sink;
mod stderr;
mod stdin;
mod stdio;
mod stdout;
mod timeout;
pub use stderr::{stderr, Stderr};
pub use stdin::{stdin, Stdin};
pub use stdout::{stdout, Stdout};
pub use timeout::timeout;

mod timeout;
mod stderr;
mod stdin;
mod stdio;
mod stdout;
}

cfg_unstable! {
pub use stderr::StderrLock;
Expand Down
43 changes: 29 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! # Async version of the Rust standard library
//!
//! `async-std` is a foundation of portable Rust software, a set of minimal and battle-tested
//! shared abstractions for the [broader Rust ecosystem][crates.io]. It offers core types, like
//! shared abstractions for the [broader Rust ecosystem][crates.io]. It offers std types, like
//! [`Future`] and [`Stream`], library-defined [operations on language primitives](#primitives),
//! [standard macros](#macros), [I/O] and [multithreading], among [many other things][other].
//!
Expand Down Expand Up @@ -170,8 +170,17 @@
//! version = "0.99"
//! features = ["attributes"]
//! ```
//!
//! Additionally it's possible to only use the core traits and combinators by
//! only enabling the `std` Cargo feature:
//!
//! ```toml
//! [dependencies.async-std]
//! version = "0.99"
//! default-features = false
//! features = ["std"]
//! ```

#![cfg(feature = "default")]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![allow(clippy::mutex_atomic, clippy::module_inception)]
Expand All @@ -188,16 +197,24 @@ mod utils;
#[doc(inline)]
pub use async_attributes::{main, test};

pub mod fs;
pub mod future;
pub mod io;
pub mod net;
pub mod os;
pub mod path;
pub mod prelude;
pub mod stream;
pub mod sync;
pub mod task;
#[cfg(feature = "std")]
mod macros;

cfg_std! {
pub mod future;
pub mod io;
pub mod os;
pub mod prelude;
pub mod stream;
pub mod sync;
pub mod task;
}

cfg_default! {
pub mod fs;
pub mod path;
pub mod net;
}

cfg_unstable! {
pub mod pin;
Expand All @@ -213,5 +230,3 @@ cfg_unstable! {
#[doc(inline)]
pub use std::{write, writeln};
}

mod macros;
52 changes: 52 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,55 @@ macro_rules! eprintln {
}
);
}

/// Declares task-local values.
///
/// The macro wraps any number of static declarations and makes them task-local. Attributes and
/// visibility modifiers are allowed.
///
/// Each declared value is of the accessor type [`LocalKey`].
///
/// [`LocalKey`]: task/struct.LocalKey.html
///
/// # Examples
///
/// ```
/// #
/// use std::cell::Cell;
///
/// use async_std::task;
/// use async_std::prelude::*;
///
/// task_local! {
/// static VAL: Cell<u32> = Cell::new(5);
/// }
///
/// task::block_on(async {
/// let v = VAL.with(|c| c.get());
/// assert_eq!(v, 5);
/// });
/// ```
#[cfg(feature = "default")]
#[macro_export]
macro_rules! task_local {
() => ();

($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
$(#[$attr])* $vis static $name: $crate::task::LocalKey<$t> = {
#[inline]
fn __init() -> $t {
$init
}

$crate::task::LocalKey {
__init,
__key: ::std::sync::atomic::AtomicU32::new(0),
}
};
);

($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
$crate::task_local!($(#[$attr])* $vis static $name: $t = $init);
$crate::task_local!($($rest)*);
);
}
11 changes: 8 additions & 3 deletions src/os/unix/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
//! Platform-specific extensions for Unix platforms.

pub mod fs;
pub mod io;
pub mod net;
cfg_std! {
pub mod io;
}

cfg_default! {
pub mod fs;
pub mod net;
}
4 changes: 3 additions & 1 deletion src/os/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Platform-specific extensions for Windows.

pub mod io;
cfg_std! {
pub mod io;
}
Loading