diff --git a/docs/src/concepts/futures.md b/docs/src/concepts/futures.md index a23ec072..05cc0400 100644 --- a/docs/src/concepts/futures.md +++ b/docs/src/concepts/futures.md @@ -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: ```rust,edition2018 -# use std::{fs::File, io::{self, Read}}; +# use std::{fs::File, io, io::prelude::*}; # -fn read_file(path: &str) -> Result { +fn read_file(path: &str) -> io::Result { let mut file = File::open(path)?; let mut contents = String::new(); 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 # use std::{fs::File, io::{self, Read}}; # -fn read_file(path: &str) -> Result { +fn read_file(path: &str) -> io::Result { let mut file = File::open(path)?; let mut contents = String::new(); 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 # 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 { +async fn read_file(path: &str) -> io::Result { let mut file = File::open(path).await?; let mut contents = String::new(); file.read_to_string(&mut contents).await?; @@ -124,7 +124,7 @@ async fn read_file(path: &str) -> Result { 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>` instead of immediately returning a `Result`. (Or, more precisely, generate a type for you that implements `Future>`.) +This `async` function sets up a deferred computation. When this function is called, it will produce a `Future>` instead of immediately returning a `io::Result`. (Or, more precisely, generate a type for you that implements `Future>`.) ## What does `.await` do? diff --git a/docs/src/concepts/tasks.md b/docs/src/concepts/tasks.md index 15bb82fd..d4037a3b 100644 --- a/docs/src/concepts/tasks.md +++ b/docs/src/concepts/tasks.md @@ -8,7 +8,7 @@ In `async-std`, the [`tasks`][tasks] module is responsible for this. The simples # extern crate async_std; use async_std::{fs::File, io, prelude::*, task}; -async fn read_file(path: &str) -> Result { +async fn read_file(path: &str) -> io::Result { let mut file = File::open(path).await?; let mut contents = String::new(); 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 # 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 { +# async fn read_file(path: &str) -> io::Result { # let mut file = File::open(path).await?; # let mut contents = String::new(); # file.read_to_string(&mut contents).await?;