-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ch. 17 §03: support code for motivating
Pin
- Rexport `tokio::fs::read_to_string` as `trpl::read_to_string`. - Add a no-listing example for the mutable borrow example. This will keep us honest that the code there itself compiles just fine!
- Loading branch information
1 parent
2b65e53
commit 67bd0a0
Showing
11 changed files
with
338 additions
and
20 deletions.
There are no files selected for viewing
280 changes: 280 additions & 0 deletions
280
listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
listings/ch17-async-await/no-listing-borrow-mutable-vec/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "async_await" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
trpl = { path = "../../../packages/trpl" } |
18 changes: 18 additions & 0 deletions
18
listings/ch17-async-await/no-listing-borrow-mutable-vec/src/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fn main() { | ||
trpl::block_on({ | ||
// ANCHOR: here | ||
async { | ||
let mut strings = vec![]; | ||
|
||
let a = trpl::read_to_string("test-data/hello.txt").await.unwrap(); | ||
strings.push(a.trim()); | ||
|
||
let b = trpl::read_to_string("test-data/world.txt").await.unwrap(); | ||
strings.push(b.trim()); | ||
|
||
let combined = strings.join(" "); | ||
println!("{combined}"); | ||
} | ||
// ANCHOR_END: here | ||
}); | ||
} |
1 change: 1 addition & 0 deletions
1
listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/hello.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello |
1 change: 1 addition & 0 deletions
1
listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/punct.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
! |
1 change: 1 addition & 0 deletions
1
listings/ch17-async-await/no-listing-borrow-mutable-vec/test-data/world.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
World |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is some text! |
Oops, something went wrong.