Skip to content
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

pin-utils crate & remove glob imports #1185

Merged
merged 2 commits into from
Aug 7, 2018
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
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@

## Usage

First, add this to your `Cargo.toml`:
Add this to your `Cargo.toml`:

```toml
[dependencies]
futures-preview = "0.3.0-alpha.2"
```

Next, add this to your crate:
Now, you can use futures-rs:

```rust
extern crate futures; // Note: It's not `futures_preview`

use futures::future::Future;
use futures::future::Future; // Note: It's not `futures_preview`
```

### Feature `std`
Expand Down
1 change: 1 addition & 0 deletions futures-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ futures-core-preview = { path = "../futures-core", version = "0.3.0-alpha.2", de

[dev-dependencies]
futures-preview = { path = "../futures", version = "0.3.0-alpha.2", default-features = true }
pin-utils = "0.1.0-alpha.1"
28 changes: 10 additions & 18 deletions futures-channel/benches/sync_mpsc.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#![feature(test, futures_api, pin, arbitrary_self_types)]

#[macro_use]
extern crate futures;
extern crate test;

use futures::task::{self, Wake, LocalWaker};
use futures::ready;
use futures::channel::mpsc::{self, Sender, UnboundedSender};
use futures::executor::LocalPool;
use futures::prelude::*;
use futures::channel::mpsc::{
unbounded,
channel,
Sender,
UnboundedSender,
};

use futures::stream::{Stream, StreamExt};
use futures::sink::Sink;
use futures::task::{self, Poll, Wake, LocalWaker};
use std::mem::PinMut;
use std::sync::Arc;
use test::Bencher;
Expand Down Expand Up @@ -41,7 +33,7 @@ fn noop_cx(f: impl FnOnce(&mut task::Context)) {
fn unbounded_1_tx(b: &mut Bencher) {
noop_cx(|cx| {
b.iter(|| {
let (tx, mut rx) = unbounded();
let (tx, mut rx) = mpsc::unbounded();

// 1000 iterations to avoid measuring overhead of initialization
// Result should be divided by 1000
Expand All @@ -64,7 +56,7 @@ fn unbounded_1_tx(b: &mut Bencher) {
fn unbounded_100_tx(b: &mut Bencher) {
noop_cx(|cx| {
b.iter(|| {
let (tx, mut rx) = unbounded();
let (tx, mut rx) = mpsc::unbounded();

let tx: Vec<_> = (0..100).map(|_| tx.clone()).collect();

Expand All @@ -86,7 +78,7 @@ fn unbounded_100_tx(b: &mut Bencher) {
fn unbounded_uncontended(b: &mut Bencher) {
noop_cx(|cx| {
b.iter(|| {
let (tx, mut rx) = unbounded();
let (tx, mut rx) = mpsc::unbounded();

for i in 0..1000 {
UnboundedSender::unbounded_send(&tx, i).expect("send");
Expand Down Expand Up @@ -127,7 +119,7 @@ impl Stream for TestSender {
fn bounded_1_tx(b: &mut Bencher) {
noop_cx(|cx| {
b.iter(|| {
let (tx, mut rx) = channel(0);
let (tx, mut rx) = mpsc::channel(0);

let mut tx = TestSender { tx, last: 0 };

Expand All @@ -146,7 +138,7 @@ fn bounded_100_tx(b: &mut Bencher) {
noop_cx(|cx| {
b.iter(|| {
// Each sender can send one item after specified capacity
let (tx, mut rx) = channel(0);
let (tx, mut rx) = mpsc::channel(0);

let mut tx: Vec<_> = (0..100).map(|_| {
TestSender {
Expand Down
5 changes: 0 additions & 5 deletions futures-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

#![doc(html_root_url = "https://rust-lang-nursery.github.io/futures-doc/0.3.0-alpha.2/futures_channel")]

#[cfg(feature = "std")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't think about that. We'll have to take care not to accidentally use std symbols in our no_std build, because there won't be anything preventing them in CI (since std is still reachable via a path).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that'd get it. I opened rust-lang/rust#53166 to discuss this.

extern crate std;

extern crate futures_core;

macro_rules! if_std {
($($i:item)*) => ($(
#[cfg(feature = "std")]
Expand Down
20 changes: 9 additions & 11 deletions futures-channel/src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,22 @@ struct Inner<T> {
///
/// ```
/// use futures::channel::oneshot;
/// use futures::prelude::*;
/// use futures::future::FutureExt;
/// use std::thread;
///
/// fn main() {
/// let (sender, receiver) = oneshot::channel::<i32>();
/// let (sender, receiver) = oneshot::channel::<i32>();
///
/// # let t =
/// thread::spawn(|| {
/// let future = receiver.map(|i| {
/// println!("got: {:?}", i);
/// });
/// // ...
/// # return future;
/// thread::spawn(|| {
/// let future = receiver.map(|i| {
/// println!("got: {:?}", i);
/// });
/// // ...
/// # return future;
/// });
///
/// sender.send(3).unwrap();
/// sender.send(3).unwrap();
/// # futures::executor::block_on(t.join().unwrap());
/// }
/// ```
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
let inner = Arc::new(Inner::new());
Expand Down
14 changes: 6 additions & 8 deletions futures-channel/tests/channel.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#![feature(async_await, await_macro, futures_api)]

extern crate futures;

use std::sync::atomic::*;
use std::thread;

use futures::prelude::*;
use futures::future::poll_fn;
use futures::executor::block_on;
use futures::channel::mpsc;
use futures::executor::block_on;
use futures::future::poll_fn;
use futures::stream::StreamExt;
use futures::sink::SinkExt;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::thread;

#[test]
fn sequence() {
Expand Down
12 changes: 5 additions & 7 deletions futures-channel/tests/mpsc-close.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
extern crate futures;

use std::thread;

use futures::prelude::*;
use futures::channel::mpsc::*;
use futures::channel::mpsc;
use futures::executor::block_on;
use futures::sink::SinkExt;
use futures::stream::StreamExt;
use std::thread;

#[test]
fn smoke() {
let (mut sender, receiver) = channel(1);
let (mut sender, receiver) = mpsc::channel(1);

let t = thread::spawn(move || {
while let Ok(()) = block_on(sender.send(42)) {}
Expand Down
18 changes: 8 additions & 10 deletions futures-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#![feature(futures_api, async_await, await_macro, pin)]

#[macro_use]
extern crate futures;

use std::thread;
use futures::channel::{mpsc, oneshot};
use futures::executor::{block_on, block_on_stream};
use futures::future::{FutureExt, poll_fn};
use futures::stream::{Stream, StreamExt};
use futures::sink::{Sink, SinkExt};
use futures::task::Poll;
use pin_utils::pin_mut;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};

use futures::prelude::*;
use futures::future::poll_fn;
use futures::channel::mpsc;
use futures::channel::oneshot;
use futures::executor::{block_on, block_on_stream};
use std::thread;

trait AssertSend: Send {}
impl AssertSend for mpsc::Sender<i32> {}
Expand Down
26 changes: 11 additions & 15 deletions futures-channel/tests/oneshot.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
#![feature(futures_api, arbitrary_self_types, pin)]

extern crate futures;

use futures::channel::oneshot::{self, Sender};
use futures::executor::block_on;
use futures::future::{Future, FutureExt, poll_fn};
use futures::task::{self, Poll};
use std::mem::PinMut;
use std::sync::mpsc;
use std::thread;

use futures::future::poll_fn;
use futures::prelude::*;
use futures::task;
use futures::channel::oneshot::*;
use futures::executor::block_on;

#[test]
fn smoke_poll() {
let (mut tx, rx) = channel::<u32>();
let (mut tx, rx) = oneshot::channel::<u32>();
let mut rx = Some(rx);
let f = poll_fn(|cx| {
assert!(tx.poll_cancel(cx).is_pending());
Expand All @@ -30,7 +26,7 @@ fn smoke_poll() {

#[test]
fn cancel_notifies() {
let (tx, rx) = channel::<u32>();
let (tx, rx) = oneshot::channel::<u32>();

let t = thread::spawn(|| {
block_on(WaitForCancel { tx: tx });
Expand Down Expand Up @@ -62,7 +58,7 @@ fn cancel_lots() {
});

for _ in 0..20000 {
let (otx, orx) = channel::<u32>();
let (otx, orx) = oneshot::channel::<u32>();
let (tx2, rx2) = mpsc::channel();
tx.send((otx, tx2)).unwrap();
drop(orx);
Expand All @@ -75,7 +71,7 @@ fn cancel_lots() {

#[test]
fn close() {
let (mut tx, mut rx) = channel::<u32>();
let (mut tx, mut rx) = oneshot::channel::<u32>();
rx.close();
block_on(poll_fn(|cx| {
match rx.poll_unpin(cx) {
Expand All @@ -89,7 +85,7 @@ fn close() {

#[test]
fn close_wakes() {
let (tx, mut rx) = channel::<u32>();
let (tx, mut rx) = oneshot::channel::<u32>();
let (tx2, rx2) = mpsc::channel();
let t = thread::spawn(move || {
rx.close();
Expand All @@ -102,7 +98,7 @@ fn close_wakes() {

#[test]
fn is_canceled() {
let (tx, rx) = channel::<u32>();
let (tx, rx) = oneshot::channel::<u32>();
assert!(!tx.is_canceled());
drop(rx);
assert!(tx.is_canceled());
Expand All @@ -118,7 +114,7 @@ fn cancel_sends() {
});

for _ in 0..20000 {
let (otx, mut orx) = channel::<u32>();
let (otx, mut orx) = oneshot::channel::<u32>();
tx.send(otx).unwrap();

orx.close();
Expand Down
6 changes: 0 additions & 6 deletions futures-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

#![doc(html_root_url = "https://rust-lang-nursery.github.io/futures-doc/0.3.0-alpha.2/futures_core")]

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "either")]
extern crate either;

#[doc(hidden)] pub use crate::future::Future;
#[doc(hidden)] pub use crate::future::TryFuture;

Expand Down
1 change: 1 addition & 0 deletions futures-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ futures-util-preview = { path = "../futures-util", version = "0.3.0-alpha.2", de
futures-channel-preview = { path = "../futures-channel", version = "0.3.0-alpha.2", default-features = false}
num_cpus = { version = "1.0", optional = true }
lazy_static = { version = "1.0", optional = true }
pin-utils = "0.1.0-alpha.1"

[dev-dependencies]
futures-preview = { path = "../futures", version = "0.3.0-alpha.2" }
Expand Down
10 changes: 3 additions & 7 deletions futures-executor/benches/poll.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#![feature(test, pin, arbitrary_self_types, futures_api)]

extern crate futures;
extern crate test;

use futures::prelude::*;
use futures::task::{self, Waker, LocalWaker, Wake, local_waker_from_nonlocal};
use futures::executor::LocalPool;

use futures::future::{Future, FutureExt};
use futures::task::{self, Poll, Waker, LocalWaker, Wake};
use std::marker::Unpin;
use std::mem::PinMut;
use std::sync::Arc;
Expand All @@ -19,7 +15,7 @@ fn notify_noop() -> LocalWaker {
fn wake(_: &Arc<Self>) {}
}

local_waker_from_nonlocal(Arc::new(Noop))
task::local_waker_from_nonlocal(Arc::new(Noop))
}

#[bench]
Expand Down
11 changes: 3 additions & 8 deletions futures-executor/benches/thread_notify.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#![feature(test, futures_api, pin, arbitrary_self_types)]

extern crate futures;
extern crate test;

use futures::executor::block_on;
use futures::future::Future;
use futures::task::{self, Poll, Waker};
use std::marker::Unpin;
use std::mem::PinMut;

use futures::prelude::*;
use futures::task::{self, Waker};
use futures::executor::block_on;

use test::Bencher;

#[bench]
Expand Down
7 changes: 2 additions & 5 deletions futures-executor/src/enter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ pub struct EnterError {
/// execute a tasks, and drop the returned [`Enter`](Enter) value after
/// completing task execution:
///
/// ```rust
/// # extern crate futures;
/// # use futures::executor::enter;
/// ```
/// use futures::executor::enter;
///
/// # fn main() {
/// let enter = enter().expect("...");
/// /* run task */
/// drop(enter);
/// # }
/// ```
///
/// Doing so ensures that executors aren't
Expand Down
7 changes: 0 additions & 7 deletions futures-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

#![doc(html_root_url = "https://rust-lang-nursery.github.io/futures-doc/0.3.0-alpha.2/futures_executor")]

#[cfg(feature = "std")]
#[macro_use]
extern crate futures_util;

macro_rules! if_std {
($($i:item)*) => ($(
#[cfg(feature = "std")]
Expand All @@ -21,9 +17,6 @@ macro_rules! if_std {
}

if_std! {
#[macro_use]
extern crate lazy_static;

mod local_pool;
pub use crate::local_pool::{block_on, block_on_stream, BlockingStream, LocalPool, LocalExecutor};

Expand Down
Loading