mirror of
https://github.com/async-rs/async-std.git
synced 2025-02-28 15:19:41 +00:00
Fix more compilation errors in the book
This commit is contained in:
parent
f2ca3f37a9
commit
217e435e8e
7 changed files with 15 additions and 15 deletions
|
@ -67,7 +67,7 @@ Note that this return value talks about the past. The past has a drawback: all d
|
|||
But we wanted to abstract over *computation* and let someone else choose how to run it. That's fundamentally incompatible with looking at the results of previous computation all the time. So, let's find a type that *describes* a computation without running it. Let's look at the function again:
|
||||
|
||||
```rust,edition2018
|
||||
# use std::{fs::File, io::{self, Read}};
|
||||
# use std::{fs::File, io, io::prelude::*};
|
||||
#
|
||||
fn read_file(path: &str) -> io::Result<String> {
|
||||
let mut file = File::open(path)?;
|
||||
|
|
|
@ -29,7 +29,7 @@ Now we can write the server's accept loop:
|
|||
# extern crate async_std;
|
||||
# use async_std::{
|
||||
# net::{TcpListener, ToSocketAddrs},
|
||||
# prelude::Stream,
|
||||
# prelude::*,
|
||||
# };
|
||||
#
|
||||
# type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
|
||||
|
@ -66,7 +66,7 @@ Finally, let's add main:
|
|||
# extern crate async_std;
|
||||
# use async_std::{
|
||||
# net::{TcpListener, ToSocketAddrs},
|
||||
# prelude::Stream,
|
||||
# prelude::*,
|
||||
# task,
|
||||
# };
|
||||
#
|
||||
|
|
|
@ -15,9 +15,8 @@ The order of events "Bob sends message to Alice" and "Alice joins" is determined
|
|||
# extern crate futures_channel;
|
||||
# extern crate futures_util;
|
||||
# use async_std::{
|
||||
# io::{Write},
|
||||
# net::TcpStream,
|
||||
# prelude::{Future, Stream},
|
||||
# prelude::*,
|
||||
# task,
|
||||
# };
|
||||
# use futures_channel::mpsc;
|
||||
|
|
|
@ -72,7 +72,7 @@ We use the `select` macro for this purpose:
|
|||
# extern crate async_std;
|
||||
# extern crate futures_channel;
|
||||
# extern crate futures_util;
|
||||
# use async_std::{io::Write, net::TcpStream};
|
||||
# use async_std::{net::TcpStream, prelude::*};
|
||||
use futures_channel::mpsc;
|
||||
use futures_util::{select, FutureExt, StreamExt};
|
||||
# use std::sync::Arc;
|
||||
|
@ -125,8 +125,9 @@ The final code looks like this:
|
|||
# extern crate futures_channel;
|
||||
# extern crate futures_util;
|
||||
use async_std::{
|
||||
io::{BufReader, BufRead, Write},
|
||||
io::BufReader,
|
||||
net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||
prelude::*,
|
||||
task,
|
||||
};
|
||||
use futures_channel::mpsc;
|
||||
|
|
|
@ -18,8 +18,9 @@ With async, we can just use the `select!` macro.
|
|||
# extern crate async_std;
|
||||
# extern crate futures_util;
|
||||
use async_std::{
|
||||
io::{stdin, BufRead, BufReader, Write},
|
||||
io::{stdin, BufReader},
|
||||
net::{TcpStream, ToSocketAddrs},
|
||||
prelude::*,
|
||||
task,
|
||||
};
|
||||
use futures_util::{select, FutureExt, StreamExt};
|
||||
|
|
|
@ -10,9 +10,9 @@ We need to:
|
|||
```rust,edition2018
|
||||
# extern crate async_std;
|
||||
# use async_std::{
|
||||
# io::{BufRead, BufReader},
|
||||
# io::BufReader,
|
||||
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||
# prelude::Stream,
|
||||
# prelude::*,
|
||||
# task,
|
||||
# };
|
||||
#
|
||||
|
@ -75,9 +75,9 @@ We can "fix" it by waiting for the task to be joined, like this:
|
|||
# #![feature(async_closure)]
|
||||
# extern crate async_std;
|
||||
# use async_std::{
|
||||
# io::{BufRead, BufReader},
|
||||
# io::BufReader,
|
||||
# net::{TcpListener, TcpStream, ToSocketAddrs},
|
||||
# prelude::Stream,
|
||||
# prelude::*,
|
||||
# task,
|
||||
# };
|
||||
#
|
||||
|
@ -125,7 +125,7 @@ So let's use a helper function for this:
|
|||
# extern crate async_std;
|
||||
# use async_std::{
|
||||
# io,
|
||||
# prelude::Future,
|
||||
# prelude::*,
|
||||
# task,
|
||||
# };
|
||||
fn spawn_and_log_error<F>(fut: F) -> task::JoinHandle<()>
|
||||
|
|
|
@ -16,9 +16,8 @@ if Alice and Charley send two messages to Bob at the same time, Bob will see the
|
|||
# extern crate futures_channel;
|
||||
# extern crate futures_util;
|
||||
# use async_std::{
|
||||
# io::Write,
|
||||
# net::TcpStream,
|
||||
# prelude::Stream,
|
||||
# prelude::*,
|
||||
# };
|
||||
use futures_channel::mpsc; // 1
|
||||
use futures_util::sink::SinkExt;
|
||||
|
|
Loading…
Reference in a new issue