Fix book to use futures_channel and futures_util, re-enable testing (#172)

* Fix book to use futures_channel and futures_util, re-enable testing

* Make dev dependencies for the book explicit
pull/174/head^2
James Munns 5 years ago committed by Yoshua Wuyts
parent 7d635b3200
commit a8090be3eb

@ -35,16 +35,15 @@ matrix:
script: script:
- cargo doc --features docs - cargo doc --features docs
# TODO(yoshuawuyts): re-enable mdbook - name: book
# - name: book rust: nightly
# rust: nightly os: linux
# os: linux before_script:
# before_script: - test -x $HOME/.cargo/bin/mdbook || ./ci/install-mdbook.sh
# - test -x $HOME/.cargo/bin/mdbook || ./ci/install-mdbook.sh - cargo build # to find 'extern crate async_std' by `mdbook test`
# - cargo build # to find 'extern crate async_std' by `mdbook test` script:
# script: - mdbook build docs
# - mdbook build docs - mdbook test -L ./target/debug/deps docs
# - mdbook test -L ./target/debug/deps docs
script: script:
- cargo check --features unstable --all --benches --bins --examples --tests - cargo check --features unstable --all --benches --bins --examples --tests

@ -44,6 +44,10 @@ femme = "1.2.0"
surf = "1.0.2" surf = "1.0.2"
tempdir = "0.3.7" tempdir = "0.3.7"
# These are used by the book for examples
futures-channel-preview = "0.3.0-alpha.18"
futures-util-preview = "0.3.0-alpha.18"
[dev-dependencies.futures-preview] [dev-dependencies.futures-preview]
version = "0.3.0-alpha.18" version = "0.3.0-alpha.18"
features = ["std", "nightly", "async-await"] features = ["std", "nightly", "async-await"]

@ -4,17 +4,16 @@ 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; # extern crate futures_channel;
# 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::{ use futures_channel::mpsc;
channel::mpsc, use futures_util::SinkExt;
SinkExt,
};
use std::{ use std::{
collections::hash_map::{HashMap, Entry}, collections::hash_map::{HashMap, Entry},
sync::Arc, sync::Arc,

@ -22,17 +22,16 @@ Let's add waiting to the server:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_channel;
# 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::{ # use futures_channel::mpsc;
# channel::mpsc, # use futures_util::SinkExt;
# SinkExt,
# };
# use std::{ # use std::{
# collections::hash_map::{HashMap, Entry}, # collections::hash_map::{HashMap, Entry},
# sync::Arc, # sync::Arc,
@ -156,17 +155,16 @@ And to the broker:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_channel;
# 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::{ # use futures_channel::mpsc;
# channel::mpsc, # use futures_util::SinkExt;
# SinkExt,
# };
# use std::{ # use std::{
# collections::hash_map::{HashMap, Entry}, # collections::hash_map::{HashMap, Entry},
# sync::Arc, # sync::Arc,

@ -12,15 +12,16 @@ 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; # extern crate futures_channel;
# extern crate futures_util;
# use async_std::{ # use async_std::{
# io::{Write}, # io::{Write},
# net::TcpStream, # net::TcpStream,
# prelude::{Future, Stream}, # prelude::{Future, Stream},
# task, # task,
# }; # };
# use futures::channel::mpsc; # use futures_channel::mpsc;
# use futures::sink::SinkExt; # use futures_util::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,9 +19,11 @@ First, let's add a shutdown channel to the `client`:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_channel;
# extern crate futures_util;
# use async_std::net::TcpStream; # use async_std::net::TcpStream;
# use futures::{channel::mpsc, SinkExt}; # use futures_channel::mpsc;
# use futures_util::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>>;
@ -68,9 +70,11 @@ We use the `select` macro for this purpose:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_channel;
# extern crate futures_util;
# use async_std::{io::Write, net::TcpStream}; # use async_std::{io::Write, net::TcpStream};
use futures::{channel::mpsc, select, FutureExt, StreamExt}; use futures_channel::mpsc;
use futures_util::{select, FutureExt, StreamExt};
# use std::sync::Arc; # use std::sync::Arc;
# type Receiver<T> = mpsc::UnboundedReceiver<T>; # type Receiver<T> = mpsc::UnboundedReceiver<T>;
@ -118,15 +122,18 @@ The final code looks like this:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_channel;
# extern crate futures_util;
use async_std::{ use async_std::{
io::{BufReader, BufRead, Write}, io::{BufReader, BufRead, Write},
net::{TcpListener, TcpStream, ToSocketAddrs}, net::{TcpListener, TcpStream, ToSocketAddrs},
task, task,
}; };
use futures::{channel::mpsc, future::Future, select, FutureExt, SinkExt, StreamExt}; use futures_channel::mpsc;
use futures_util::{select, FutureExt, SinkExt, StreamExt};
use std::{ use std::{
collections::hash_map::{Entry, HashMap}, collections::hash_map::{Entry, HashMap},
future::Future,
sync::Arc, sync::Arc,
}; };

@ -16,13 +16,13 @@ With async, we can just use the `select!` macro.
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# extern crate futures; # extern crate futures_util;
use async_std::{ use async_std::{
io::{stdin, BufRead, BufReader, Write}, io::{stdin, BufRead, BufReader, Write},
net::{TcpStream, ToSocketAddrs}, net::{TcpStream, ToSocketAddrs},
task, task,
}; };
use futures::{select, FutureExt, StreamExt}; use futures_util::{select, FutureExt, StreamExt};
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,15 @@ 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; # extern crate futures_channel;
# extern crate futures_util;
# use async_std::{ # use async_std::{
# io::Write, # io::Write,
# net::TcpStream, # net::TcpStream,
# prelude::Stream, # prelude::Stream,
# }; # };
use futures::channel::mpsc; // 1 use futures_channel::mpsc; // 1
use futures::sink::SinkExt; use futures_util::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>>;

Loading…
Cancel
Save