2
0
Fork 1
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:
Stjepan Glavina 2019-09-22 12:03:56 +02:00
parent f2ca3f37a9
commit 217e435e8e
7 changed files with 15 additions and 15 deletions

View file

@ -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: 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 ```rust,edition2018
# use std::{fs::File, io::{self, Read}}; # use std::{fs::File, io, io::prelude::*};
# #
fn read_file(path: &str) -> io::Result<String> { fn read_file(path: &str) -> io::Result<String> {
let mut file = File::open(path)?; let mut file = File::open(path)?;

View file

@ -29,7 +29,7 @@ Now we can write the server's accept loop:
# extern crate async_std; # extern crate async_std;
# use async_std::{ # use async_std::{
# net::{TcpListener, ToSocketAddrs}, # net::{TcpListener, ToSocketAddrs},
# prelude::Stream, # prelude::*,
# }; # };
# #
# 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>>;
@ -66,7 +66,7 @@ Finally, let's add main:
# extern crate async_std; # extern crate async_std;
# use async_std::{ # use async_std::{
# net::{TcpListener, ToSocketAddrs}, # net::{TcpListener, ToSocketAddrs},
# prelude::Stream, # prelude::*,
# task, # task,
# }; # };
# #

View file

@ -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_channel;
# extern crate futures_util; # extern crate futures_util;
# use async_std::{ # use async_std::{
# io::{Write},
# net::TcpStream, # net::TcpStream,
# prelude::{Future, Stream}, # prelude::*,
# task, # task,
# }; # };
# use futures_channel::mpsc; # use futures_channel::mpsc;

View file

@ -72,7 +72,7 @@ We use the `select` macro for this purpose:
# extern crate async_std; # extern crate async_std;
# extern crate futures_channel; # extern crate futures_channel;
# extern crate futures_util; # extern crate futures_util;
# use async_std::{io::Write, net::TcpStream}; # use async_std::{net::TcpStream, prelude::*};
use futures_channel::mpsc; use futures_channel::mpsc;
use futures_util::{select, FutureExt, StreamExt}; use futures_util::{select, FutureExt, StreamExt};
# use std::sync::Arc; # use std::sync::Arc;
@ -125,8 +125,9 @@ The final code looks like this:
# extern crate futures_channel; # extern crate futures_channel;
# extern crate futures_util; # extern crate futures_util;
use async_std::{ use async_std::{
io::{BufReader, BufRead, Write}, io::BufReader,
net::{TcpListener, TcpStream, ToSocketAddrs}, net::{TcpListener, TcpStream, ToSocketAddrs},
prelude::*,
task, task,
}; };
use futures_channel::mpsc; use futures_channel::mpsc;

View file

@ -18,8 +18,9 @@ With async, we can just use the `select!` macro.
# extern crate async_std; # extern crate async_std;
# extern crate futures_util; # extern crate futures_util;
use async_std::{ use async_std::{
io::{stdin, BufRead, BufReader, Write}, io::{stdin, BufReader},
net::{TcpStream, ToSocketAddrs}, net::{TcpStream, ToSocketAddrs},
prelude::*,
task, task,
}; };
use futures_util::{select, FutureExt, StreamExt}; use futures_util::{select, FutureExt, StreamExt};

View file

@ -10,9 +10,9 @@ We need to:
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# use async_std::{ # use async_std::{
# io::{BufRead, BufReader}, # io::BufReader,
# net::{TcpListener, TcpStream, ToSocketAddrs}, # net::{TcpListener, TcpStream, ToSocketAddrs},
# prelude::Stream, # prelude::*,
# task, # task,
# }; # };
# #
@ -75,9 +75,9 @@ We can "fix" it by waiting for the task to be joined, like this:
# #![feature(async_closure)] # #![feature(async_closure)]
# extern crate async_std; # extern crate async_std;
# use async_std::{ # use async_std::{
# io::{BufRead, BufReader}, # io::BufReader,
# net::{TcpListener, TcpStream, ToSocketAddrs}, # net::{TcpListener, TcpStream, ToSocketAddrs},
# prelude::Stream, # prelude::*,
# task, # task,
# }; # };
# #
@ -125,7 +125,7 @@ So let's use a helper function for this:
# extern crate async_std; # extern crate async_std;
# use async_std::{ # use async_std::{
# io, # io,
# prelude::Future, # prelude::*,
# task, # task,
# }; # };
fn spawn_and_log_error<F>(fut: F) -> task::JoinHandle<()> fn spawn_and_log_error<F>(fut: F) -> task::JoinHandle<()>

View file

@ -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_channel;
# extern crate futures_util; # extern crate futures_util;
# use async_std::{ # use async_std::{
# io::Write,
# net::TcpStream, # net::TcpStream,
# prelude::Stream, # prelude::*,
# }; # };
use futures_channel::mpsc; // 1 use futures_channel::mpsc; // 1
use futures_util::sink::SinkExt; use futures_util::sink::SinkExt;