mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
Update futures to 0.3 (#463)
* Update futures to 0.3 * Fix a search-and-replace error * Fix imports in tests * Fix an import
This commit is contained in:
parent
93b01e36ed
commit
c34e0f8a35
9 changed files with 34 additions and 46 deletions
10
Cargo.toml
10
Cargo.toml
|
@ -32,8 +32,8 @@ broadcaster = { version = "0.2.6", optional = true, default-features = false, fe
|
||||||
crossbeam-channel = "0.3.9"
|
crossbeam-channel = "0.3.9"
|
||||||
crossbeam-deque = "0.7.1"
|
crossbeam-deque = "0.7.1"
|
||||||
crossbeam-utils = "0.6.6"
|
crossbeam-utils = "0.6.6"
|
||||||
futures-core-preview = "=0.3.0-alpha.19"
|
futures-core = "0.3.0"
|
||||||
futures-io-preview = "=0.3.0-alpha.19"
|
futures-io = "0.3.0"
|
||||||
futures-timer = "1.0.2"
|
futures-timer = "1.0.2"
|
||||||
kv-log-macro = "1.0.4"
|
kv-log-macro = "1.0.4"
|
||||||
log = { version = "0.4.8", features = ["kv_unstable"] }
|
log = { version = "0.4.8", features = ["kv_unstable"] }
|
||||||
|
@ -51,11 +51,7 @@ femme = "1.2.0"
|
||||||
rand = "0.7.2"
|
rand = "0.7.2"
|
||||||
# surf = "1.0.2"
|
# surf = "1.0.2"
|
||||||
tempdir = "0.3.7"
|
tempdir = "0.3.7"
|
||||||
futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] }
|
futures = "0.3.0"
|
||||||
|
|
||||||
# These are used by the book for examples
|
|
||||||
futures-channel-preview = "=0.3.0-alpha.19"
|
|
||||||
futures-util-preview = "=0.3.0-alpha.19"
|
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "stream"
|
name = "stream"
|
||||||
|
|
|
@ -4,16 +4,15 @@ At this point, we only need to start the broker to get a fully-functioning (in t
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
use async_std::{
|
use async_std::{
|
||||||
io::{self, BufReader},
|
io::{self, BufReader},
|
||||||
net::{TcpListener, TcpStream, ToSocketAddrs},
|
net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
task,
|
task,
|
||||||
};
|
};
|
||||||
use futures_channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use futures_util::SinkExt;
|
use futures::SinkExt;
|
||||||
use std::{
|
use std::{
|
||||||
collections::hash_map::{HashMap, Entry},
|
collections::hash_map::{HashMap, Entry},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
|
|
@ -22,16 +22,15 @@ Let's add waiting to the server:
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::{
|
# use async_std::{
|
||||||
# io::{self, BufReader},
|
# io::{self, BufReader},
|
||||||
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||||
# prelude::*,
|
# prelude::*,
|
||||||
# task,
|
# task,
|
||||||
# };
|
# };
|
||||||
# use futures_channel::mpsc;
|
# use futures::channel::mpsc;
|
||||||
# use futures_util::SinkExt;
|
# use futures::SinkExt;
|
||||||
# use std::{
|
# use std::{
|
||||||
# collections::hash_map::{HashMap, Entry},
|
# collections::hash_map::{HashMap, Entry},
|
||||||
# sync::Arc,
|
# sync::Arc,
|
||||||
|
@ -156,16 +155,15 @@ And to the broker:
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::{
|
# use async_std::{
|
||||||
# io::{self, BufReader},
|
# io::{self, BufReader},
|
||||||
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||||
# prelude::*,
|
# prelude::*,
|
||||||
# task,
|
# task,
|
||||||
# };
|
# };
|
||||||
# use futures_channel::mpsc;
|
# use futures::channel::mpsc;
|
||||||
# use futures_util::SinkExt;
|
# use futures::SinkExt;
|
||||||
# use std::{
|
# use std::{
|
||||||
# collections::hash_map::{HashMap, Entry},
|
# collections::hash_map::{HashMap, Entry},
|
||||||
# sync::Arc,
|
# sync::Arc,
|
||||||
|
|
|
@ -12,15 +12,14 @@ The order of events "Bob sends message to Alice" and "Alice joins" is determined
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::{
|
# use async_std::{
|
||||||
# net::TcpStream,
|
# net::TcpStream,
|
||||||
# prelude::*,
|
# prelude::*,
|
||||||
# task,
|
# task,
|
||||||
# };
|
# };
|
||||||
# use futures_channel::mpsc;
|
# use futures::channel::mpsc;
|
||||||
# use futures_util::sink::SinkExt;
|
# use futures::sink::SinkExt;
|
||||||
# use std::sync::Arc;
|
# use std::sync::Arc;
|
||||||
#
|
#
|
||||||
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
|
@ -19,11 +19,10 @@ First, let's add a shutdown channel to the `connection_loop`:
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::net::TcpStream;
|
# use async_std::net::TcpStream;
|
||||||
# use futures_channel::mpsc;
|
# use futures::channel::mpsc;
|
||||||
# use futures_util::SinkExt;
|
# use futures::SinkExt;
|
||||||
# use std::sync::Arc;
|
# use std::sync::Arc;
|
||||||
#
|
#
|
||||||
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
@ -70,11 +69,10 @@ We use the `select` macro for this purpose:
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::{net::TcpStream, prelude::*};
|
# use async_std::{net::TcpStream, prelude::*};
|
||||||
use futures_channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use futures_util::{select, FutureExt};
|
use futures::{select, FutureExt};
|
||||||
# use std::sync::Arc;
|
# use std::sync::Arc;
|
||||||
|
|
||||||
# type Receiver<T> = mpsc::UnboundedReceiver<T>;
|
# type Receiver<T> = mpsc::UnboundedReceiver<T>;
|
||||||
|
@ -122,16 +120,15 @@ The final code looks like this:
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
use async_std::{
|
use async_std::{
|
||||||
io::BufReader,
|
io::BufReader,
|
||||||
net::{TcpListener, TcpStream, ToSocketAddrs},
|
net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
task,
|
task,
|
||||||
};
|
};
|
||||||
use futures_channel::mpsc;
|
use futures::channel::mpsc;
|
||||||
use futures_util::{select, FutureExt, SinkExt};
|
use futures::{select, FutureExt, SinkExt};
|
||||||
use std::{
|
use std::{
|
||||||
collections::hash_map::{Entry, HashMap},
|
collections::hash_map::{Entry, HashMap},
|
||||||
future::Future,
|
future::Future,
|
||||||
|
|
|
@ -16,14 +16,14 @@ With async, we can just use the `select!` macro.
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_util;
|
# extern crate futures;
|
||||||
use async_std::{
|
use async_std::{
|
||||||
io::{stdin, BufReader},
|
io::{stdin, BufReader},
|
||||||
net::{TcpStream, ToSocketAddrs},
|
net::{TcpStream, ToSocketAddrs},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
task,
|
task,
|
||||||
};
|
};
|
||||||
use futures_util::{select, FutureExt};
|
use futures::{select, FutureExt};
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,13 @@ if Alice and Charley send two messages to Bob at the same time, Bob will see the
|
||||||
|
|
||||||
```rust,edition2018
|
```rust,edition2018
|
||||||
# extern crate async_std;
|
# extern crate async_std;
|
||||||
# extern crate futures_channel;
|
# extern crate futures;
|
||||||
# extern crate futures_util;
|
|
||||||
# use async_std::{
|
# use async_std::{
|
||||||
# net::TcpStream,
|
# net::TcpStream,
|
||||||
# prelude::*,
|
# prelude::*,
|
||||||
# };
|
# };
|
||||||
use futures_channel::mpsc; // 1
|
use futures::channel::mpsc; // 1
|
||||||
use futures_util::sink::SinkExt;
|
use futures::sink::SinkExt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
|
@ -615,9 +615,9 @@ impl Path {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
|
/// # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
|
||||||
/// #
|
/// #
|
||||||
/// use async_std::path::Path;
|
|
||||||
/// use async_std::fs;
|
/// use async_std::fs;
|
||||||
/// use futures_util::stream::StreamExt;
|
/// use async_std::path::Path;
|
||||||
|
/// use async_std::prelude::*;
|
||||||
///
|
///
|
||||||
/// let path = Path::new("/laputa");
|
/// let path = Path::new("/laputa");
|
||||||
/// let mut dir = fs::read_dir(&path).await.expect("read_dir call failed");
|
/// let mut dir = fs::read_dir(&path).await.expect("read_dir call failed");
|
||||||
|
|
|
@ -204,9 +204,9 @@ impl BarrierWaitResult {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use futures_channel::mpsc::unbounded;
|
use futures::channel::mpsc::unbounded;
|
||||||
use futures_util::sink::SinkExt;
|
use futures::sink::SinkExt;
|
||||||
use futures_util::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
|
|
||||||
use crate::sync::{Arc, Barrier};
|
use crate::sync::{Arc, Barrier};
|
||||||
use crate::task;
|
use crate::task;
|
||||||
|
|
Loading…
Reference in a new issue