Skip to content

Commit

Permalink
Merge pull request #757 from dignifiedquire/feat/smol
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored May 7, 2020
2 parents 370642e + 27c605b commit 10f7abb
Show file tree
Hide file tree
Showing 56 changed files with 842 additions and 1,619 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ jobs:
with:
command: check
args: --features unstable --all --bins --examples --tests

- name: check wasm
uses: actions-rs/cargo@v1
with:
command: check
target: wasm32-unknown-unknown
override: true
args: --features unstable --all --bins --tests

- name: check bench
uses: actions-rs/cargo@v1
Expand Down
33 changes: 19 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.5.0"
authors = [
"Stjepan Glavina <[email protected]>",
"Yoshua Wuyts <[email protected]>",
"Friedel Ziegelmayer <[email protected]>",
"Contributors to async-std",
]
edition = "2018"
Expand All @@ -24,19 +25,13 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
default = [
"std",
"async-task",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-queue",
"futures-timer",
"kv-log-macro",
"log",
"mio",
"mio-uds",
"num_cpus",
"pin-project-lite",
]
docs = ["attributes", "unstable", "default"]
unstable = ["std", "broadcaster", "futures-timer"]
unstable = ["std", "broadcaster"]
attributes = ["async-attributes"]
std = [
"alloc",
Expand All @@ -47,6 +42,10 @@ std = [
"once_cell",
"pin-utils",
"slab",
"smol",
"wasm-timer",
"wasm-bindgen-futures",
"futures-channel",
]
alloc = [
"futures-core/alloc",
Expand All @@ -55,32 +54,38 @@ alloc = [

[dependencies]
async-attributes = { version = "1.1.1", optional = true }
async-task = { version = "1.3.1", optional = true }
async-task = { version = "3.0.0", optional = true }
broadcaster = { version = "1.0.0", optional = true }
crossbeam-channel = { version = "0.4.2", optional = true }
crossbeam-deque = { version = "0.7.3", optional = true }
crossbeam-queue = { version = "0.2.0", optional = true }
crossbeam-utils = { version = "0.7.2", optional = true }
futures-core = { version = "0.3.4", optional = true, default-features = false }
futures-io = { version = "0.3.4", optional = true }
futures-timer = { version = "3.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.3.3", optional = true }
mio = { version = "0.6.19", optional = true }
mio-uds = { version = "0.6.7", optional = true }
num_cpus = { version = "1.12.0", optional = true }
once_cell = { version = "1.3.1", optional = true }
pin-project-lite = { version = "0.1.4", optional = true }
pin-utils = { version = "0.1.0-alpha.4", optional = true }
slab = { version = "0.4.2", optional = true }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
smol = { version = "0.1.1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-timer = { version = "0.2.4", optional = true }
wasm-bindgen-futures = { version = "0.4.10", optional = true }
futures-channel = { version = "0.3.4", optional = true }

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = "0.3.10"

[dev-dependencies]
femme = "1.3.0"
rand = "0.7.3"
surf = "1.0.3"
tempdir = "0.3.7"
futures = "0.3.4"
rand_xorshift = "0.2.0"

[[test]]
name = "stream"
Expand Down
6 changes: 3 additions & 3 deletions src/future/future/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::future::Future;
use std::pin::Pin;
use std::time::Duration;

use futures_timer::Delay;
use pin_project_lite::pin_project;

use crate::task::{Context, Poll};
use crate::utils::Timer;

pin_project! {
#[doc(hidden)]
Expand All @@ -14,13 +14,13 @@ pin_project! {
#[pin]
future: F,
#[pin]
delay: Delay,
delay: Timer,
}
}

impl<F> DelayFuture<F> {
pub fn new(future: F, dur: Duration) -> DelayFuture<F> {
let delay = Delay::new(dur);
let delay = Timer::after(dur);

DelayFuture { future, delay }
}
Expand Down
17 changes: 8 additions & 9 deletions src/future/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::error::Error;
use std::fmt;
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
use std::future::Future;

use futures_timer::Delay;
use pin_project_lite::pin_project;

use crate::task::{Context, Poll};
use crate::utils::Timer;

/// Awaits a future or times out after a duration of time.
///
Expand All @@ -33,11 +33,7 @@ pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
where
F: Future<Output = T>,
{
let f = TimeoutFuture {
future: f,
delay: Delay::new(dur),
};
f.await
TimeoutFuture::new(f, dur).await
}

pin_project! {
Expand All @@ -46,14 +42,17 @@ pin_project! {
#[pin]
future: F,
#[pin]
delay: Delay,
delay: Timer,
}
}

impl<F> TimeoutFuture<F> {
#[allow(dead_code)]
pub(super) fn new(future: F, dur: Duration) -> TimeoutFuture<F> {
TimeoutFuture { future: future, delay: Delay::new(dur) }
TimeoutFuture {
future,
delay: Timer::after(dur),
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,33 @@ cfg_std! {
cfg_default! {
// For use in the print macros.
#[doc(hidden)]
#[cfg(not(target_os = "unknown"))]
pub use stdio::{_eprint, _print};

#[cfg(not(target_os = "unknown"))]
pub use stderr::{stderr, Stderr};
#[cfg(not(target_os = "unknown"))]
pub use stdin::{stdin, Stdin};
#[cfg(not(target_os = "unknown"))]
pub use stdout::{stdout, Stdout};
pub use timeout::timeout;

mod timeout;
#[cfg(not(target_os = "unknown"))]
mod stderr;
#[cfg(not(target_os = "unknown"))]
mod stdin;
#[cfg(not(target_os = "unknown"))]
mod stdio;
#[cfg(not(target_os = "unknown"))]
mod stdout;
}

cfg_unstable_default! {
#[cfg(not(target_os = "unknown"))]
pub use stderr::StderrLock;
#[cfg(not(target_os = "unknown"))]
pub use stdin::StdinLock;
#[cfg(not(target_os = "unknown"))]
pub use stdout::StdoutLock;
}
13 changes: 6 additions & 7 deletions src/io/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::mem;

use crate::io::IoSliceMut;

pub use take::Take;
pub use bytes::Bytes;
pub use chain::Chain;
pub use take::Take;

extension_trait! {
use std::pin::Pin;
Expand Down Expand Up @@ -477,13 +477,13 @@ unsafe fn initialize<R: futures_io::AsyncRead>(_reader: &R, buf: &mut [u8]) {
std::ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len())
}

#[cfg(test)]
#[cfg(all(test, not(target_os = "unknown")))]
mod tests {
use crate::io;
use crate::prelude::*;

#[test]
fn test_read_by_ref() -> io::Result<()> {
fn test_read_by_ref() {
crate::task::block_on(async {
let mut f = io::Cursor::new(vec![0u8, 1, 2, 3, 4, 5, 6, 7, 8]);
let mut buffer = Vec::new();
Expand All @@ -493,14 +493,13 @@ mod tests {
let reference = f.by_ref();

// read at most 5 bytes
assert_eq!(reference.take(5).read_to_end(&mut buffer).await?, 5);
assert_eq!(reference.take(5).read_to_end(&mut buffer).await.unwrap(), 5);
assert_eq!(&buffer, &[0, 1, 2, 3, 4])
} // drop our &mut reference so we can use f again

// original file still usable, read the rest
assert_eq!(f.read_to_end(&mut other_buffer).await?, 4);
assert_eq!(f.read_to_end(&mut other_buffer).await.unwrap(), 4);
assert_eq!(&other_buffer, &[5, 6, 7, 8]);
Ok(())
})
});
}
}
2 changes: 1 addition & 1 deletion src/io/read/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<T: BufRead> BufRead for Take<T> {
}
}

#[cfg(test)]
#[cfg(all(test, not(target_os = "unknown")))]
mod tests {
use crate::io;
use crate::prelude::*;
Expand Down
8 changes: 4 additions & 4 deletions src/io/timeout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use std::future::Future;

use futures_timer::Delay;
use pin_project_lite::pin_project;

use crate::io;
use crate::utils::Timer;

/// Awaits an I/O future or times out after a duration of time.
///
Expand Down Expand Up @@ -37,7 +37,7 @@ where
F: Future<Output = io::Result<T>>,
{
Timeout {
timeout: Delay::new(dur),
timeout: Timer::after(dur),
future: f,
}
.await
Expand All @@ -53,7 +53,7 @@ pin_project! {
#[pin]
future: F,
#[pin]
timeout: Delay,
timeout: Timer,
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,17 @@ cfg_std! {
}

cfg_default! {
#[cfg(not(target_os = "unknown"))]
pub mod fs;
pub mod path;
pub mod net;
#[cfg(not(target_os = "unknown"))]
pub(crate) mod rt;
}

cfg_unstable! {
pub mod pin;
#[cfg(not(target_os = "unknown"))]
pub mod process;

mod unit;
Expand Down
6 changes: 6 additions & 0 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ pub use std::net::Shutdown;
pub use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
pub use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};

#[cfg(not(target_os = "unknown"))]
pub use addr::ToSocketAddrs;
#[cfg(not(target_os = "unknown"))]
pub use tcp::{Incoming, TcpListener, TcpStream};
#[cfg(not(target_os = "unknown"))]
pub use udp::UdpSocket;

#[cfg(not(target_os = "unknown"))]
mod addr;
#[cfg(not(target_os = "unknown"))]
mod tcp;
#[cfg(not(target_os = "unknown"))]
mod udp;
Loading

0 comments on commit 10f7abb

Please sign in to comment.