Fix build errors in docs

pull/224/head
Stjepan Glavina 5 years ago
parent a97d26ca13
commit f2ca3f37a9

@ -51,9 +51,9 @@ Remember the talk about "deferred computation" in the intro? That's all it is. I
Let's have a look at a simple function, specifically the return value: Let's have a look at a simple function, specifically the return value:
```rust,edition2018 ```rust,edition2018
# use std::{fs::File, io::{self, Read}}; # use std::{fs::File, io, io::prelude::*};
# #
fn read_file(path: &str) -> Result<String, io::Error> { fn read_file(path: &str) -> io::Result<String> {
let mut file = File::open(path)?; let mut file = File::open(path)?;
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents)?; file.read_to_string(&mut contents)?;
@ -69,7 +69,7 @@ But we wanted to abstract over *computation* and let someone else choose how to
```rust,edition2018 ```rust,edition2018
# use std::{fs::File, io::{self, Read}}; # use std::{fs::File, io::{self, Read}};
# #
fn read_file(path: &str) -> Result<String, io::Error> { fn read_file(path: &str) -> io::Result<String> {
let mut file = File::open(path)?; let mut file = File::open(path)?;
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents)?; file.read_to_string(&mut contents)?;
@ -112,9 +112,9 @@ While the `Future` trait has existed in Rust for a while, it was inconvenient to
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# use async_std::{fs::File, io, prelude::*}; # use async_std::{fs::File, io, io::prelude::*};
# #
async fn read_file(path: &str) -> Result<String, io::Error> { async fn read_file(path: &str) -> io::Result<String> {
let mut file = File::open(path).await?; let mut file = File::open(path).await?;
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents).await?; file.read_to_string(&mut contents).await?;
@ -124,7 +124,7 @@ async fn read_file(path: &str) -> Result<String, io::Error> {
Amazingly little difference, right? All we did is label the function `async` and insert 2 special commands: `.await`. Amazingly little difference, right? All we did is label the function `async` and insert 2 special commands: `.await`.
This `async` function sets up a deferred computation. When this function is called, it will produce a `Future<Output=Result<String, io::Error>>` instead of immediately returning a `Result<String, io::Error>`. (Or, more precisely, generate a type for you that implements `Future<Output=Result<String, io::Error>>`.) This `async` function sets up a deferred computation. When this function is called, it will produce a `Future<Output = io::Result<String>>` instead of immediately returning a `io::Result<String>`. (Or, more precisely, generate a type for you that implements `Future<Output = io::Result<String>>`.)
## What does `.await` do? ## What does `.await` do?

@ -8,7 +8,7 @@ In `async-std`, the [`tasks`][tasks] module is responsible for this. The simples
# extern crate async_std; # extern crate async_std;
use async_std::{fs::File, io, prelude::*, task}; use async_std::{fs::File, io, prelude::*, task};
async fn read_file(path: &str) -> Result<String, io::Error> { async fn read_file(path: &str) -> io::Result<String> {
let mut file = File::open(path).await?; let mut file = File::open(path).await?;
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents).await?; file.read_to_string(&mut contents).await?;
@ -33,9 +33,9 @@ This asks the runtime baked into `async_std` to execute the code that reads a fi
```rust,edition2018 ```rust,edition2018
# extern crate async_std; # extern crate async_std;
# use async_std::{fs::File, prelude::*, task}; # use async_std::{fs::File, io, prelude::*, task};
# #
# async fn read_file(path: &str) -> Result<String, io::Error> { # async fn read_file(path: &str) -> io::Result<String> {
# let mut file = File::open(path).await?; # let mut file = File::open(path).await?;
# let mut contents = String::new(); # let mut contents = String::new();
# file.read_to_string(&mut contents).await?; # file.read_to_string(&mut contents).await?;

Loading…
Cancel
Save