Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Edits for async chapter #3965

Merged
merged 31 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e774613
Ch. 17: remove 'base' listing
chriskrycho Jul 1, 2024
f039ca3
Ch. 17: Transition materials from Ch. 16 and into Ch. 18
chriskrycho Jun 27, 2024
5fdd92c
Ch. 17§00 initial edits
chriskrycho Jul 1, 2024
f023032
Ch. 17: add some more explanatory comments to `trpl`
chriskrycho Jul 1, 2024
eec1745
Ch. 17§01 initial edits for the first subsection
chriskrycho Jul 1, 2024
e238342
Ch. 17§01 initial edits for the second subsection
chriskrycho Jul 2, 2024
09b80f9
Ch. 17§02 initial edits on 'Counting'
chriskrycho Jul 2, 2024
e5c9afd
Ch. 17§02 initial edits on 'Message Passing'
chriskrycho Jul 2, 2024
89920d5
Ch. 17§03 Initial edits on opening section
chriskrycho Jul 3, 2024
655526a
Upgrade to Rust 1.79.0
carols10cents Jul 5, 2024
8c59066
Backport changes to chapter 11
carols10cents May 31, 2024
d9303e3
Don't just discard output without examining it when doing manual upda…
carols10cents Jul 5, 2024
d5670bf
Remove anchors around entire listings
carols10cents Jul 5, 2024
024ee95
Increase consistency with what cargo new --lib generates
carols10cents Jul 5, 2024
1f7ac86
Handle more non-links in code and handle them a better way
carols10cents Jul 5, 2024
010f769
Snapshot changes to generated ch11 that SHOULDN'T be sent to nostarch
carols10cents Jul 5, 2024
6a1bf5d
Snapshot changes to ch11 to consider sending to nostarch
carols10cents Jul 5, 2024
ee5c7ec
Yes, RUSTFLAGS is a word
carols10cents Jul 5, 2024
451f77b
Ch. 17§03 initial edits on pinning section
chriskrycho Jul 3, 2024
1cc4dbe
Ch. 17§03: Rename the section for clarity
chriskrycho Jul 5, 2024
cc0f913
Ch. 17: remove now unused Listing 17-24
chriskrycho Jul 5, 2024
1030015
Ch. 17§04 initial edits on intro and “Yielding” section
chriskrycho Jul 5, 2024
ef1ed96
Ch. 17§04 initial edits on Building Our Own Async Abstractions
chriskrycho Jul 8, 2024
995e932
Use Rust 2021 Edition for mdBook
chriskrycho Jul 11, 2024
67fa536
Merge pull request #3974 from rust-lang/chriskrycho/edition-in-book
chriskrycho Jul 12, 2024
074c442
Ch. 17§05 initial edits on first two sections
chriskrycho Jul 9, 2024
1a90722
Merge `main` into `async-edits`
chriskrycho Jul 11, 2024
fbcdb24
Ch. 17§05 initial edits on 'Composing Streams'
chriskrycho Jul 11, 2024
2797d95
Ch. 17§05 initial edits on 'Merging Streams'
chriskrycho Jul 11, 2024
92c19ce
Ch. 17§06 initial edits
chriskrycho Jul 12, 2024
dd155f2
Merge `main` into `async-edits`
chriskrycho Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.78 -c rust-docs
rustup default 1.78
rustup toolchain install 1.79 -c rust-docs
rustup default 1.79
- name: Install mdbook
run: |
mkdir bin
Expand All @@ -36,8 +36,8 @@ jobs:
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.76 -c rust-docs
rustup default 1.76
rustup toolchain install 1.79 -c rust-docs
rustup default 1.79
- name: Run `tools` package tests
run: |
cargo test
Expand Down
3 changes: 3 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ git-repository-url = "https://github.com/rust-lang/book"

[preprocessor.trpl-listing]
output-mode = "default"

[rust]
edition = "2021"
1 change: 1 addition & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ Rustaceans
rUsT
rustc
rustdoc
RUSTFLAGS
Rustonomicon
rustfix
rustfmt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ error[E0308]: mismatched types
= note: expected reference `&String`
found reference `&{integer}`
note: method defined here
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/cmp.rs:836:8
--> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/cmp.rs:840:8

For more information about this error, try `rustc --explain E0308`.
error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ error[E0277]: cannot add `Option<i8>` to `i8`
|
= help: the trait `Add<Option<i8>>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<i8 as Add>
<i8 as Add<&i8>>
<&'a i8 as Add<i8>>
<&i8 as Add<&i8>>
<i8 as Add<&i8>>
<i8 as Add>

For more information about this error, try `rustc --explain E0277`.
error: could not compile `enums` (bin "enums") due to 1 previous error
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ error[E0004]: non-exhaustive patterns: `None` not covered
| ^ pattern `None` not covered
|
note: `Option<i32>` defined here
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:572:1
::: /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:576:5
--> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:571:1
::: /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:575:5
|
= note: not covered
= note: the matched value is of type `Option<i32>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,5 @@ help: consider introducing a named lifetime parameter
9 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
| ++++ ++ ++ ++

error: lifetime may not live long enough
--> src/main.rs:11:9
|
9 | fn longest(x: &str, y: &str) -> &str {
| - let's call the lifetime of this reference `'1`
10 | if x.len() > y.len() {
11 | x
| ^ returning this value requires that `'1` must outlive `'static`

error: lifetime may not live long enough
--> src/main.rs:13:9
|
9 | fn longest(x: &str, y: &str) -> &str {
| - let's call the lifetime of this reference `'2`
...
13 | y
| ^ returning this value requires that `'2` must outlive `'static`

For more information about this error, try `rustc --explain E0106`.
error: could not compile `chapter10` (bin "chapter10") due to 3 previous errors
error: could not compile `chapter10` (bin "chapter10") due to 1 previous error
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: here
pub fn add(left: usize, right: usize) -> usize {
left + right
}
Expand All @@ -12,10 +11,9 @@ mod tests {
let result = add(2, 2);
assert_eq!(result, 4);
}

#[test]
fn another() {
panic!("Make this test fail");
}
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ANCHOR: here
#[derive(Debug)]
struct Rectangle {
width: u32,
Expand All @@ -10,4 +9,3 @@ impl Rectangle {
self.width > other.width && self.height > other.height
}
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
a + 2
}

Expand All @@ -8,6 +8,7 @@ mod tests {

#[test]
fn it_adds_two() {
assert_eq!(4, add_two(2));
let result = add_two(2);
assert_eq!(result, 4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ failures:
I got the value 8
thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9:
assertion `left == right` failed
left: 5
right: 10
left: 10
right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ mod tests {
#[test]
fn this_test_will_pass() {
let value = prints_and_returns_10(4);
assert_eq!(10, value);
assert_eq!(value, 10);
}

#[test]
fn this_test_will_fail() {
let value = prints_and_returns_10(8);
assert_eq!(5, value);
assert_eq!(value, 5);
}
}
11 changes: 7 additions & 4 deletions listings/ch11-writing-automated-tests/listing-11-11/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
a + 2
}

Expand All @@ -8,16 +8,19 @@ mod tests {

#[test]
fn add_two_and_two() {
assert_eq!(4, add_two(2));
let result = add_two(2);
assert_eq!(result, 4);
}

#[test]
fn add_three_and_two() {
assert_eq!(5, add_two(3));
let result = add_two(3);
assert_eq!(result, 5);
}

#[test]
fn one_hundred() {
assert_eq!(102, add_two(100));
let result = add_two(100);
assert_eq!(result, 102);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
internal_adder(a, 2)
}

fn internal_adder(a: i32, b: i32) -> i32 {
a + b
fn internal_adder(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
Expand All @@ -12,6 +12,7 @@ mod tests {

#[test]
fn internal() {
assert_eq!(4, internal_adder(2, 2));
let result = internal_adder(2, 2);
assert_eq!(result, 4);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
internal_adder(a, 2)
}

fn internal_adder(a: i32, b: i32) -> i32 {
a + b
fn internal_adder(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
Expand All @@ -12,6 +12,7 @@ mod tests {

#[test]
fn internal() {
assert_eq!(4, internal_adder(2, 2));
let result = internal_adder(2, 2);
assert_eq!(result, 4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ use adder::add_two;

#[test]
fn it_adds_two() {
assert_eq!(4, add_two(2));
let result = add_two(2);
assert_eq!(result, 4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test tests::it_adds_two ... FAILED
failures:

---- tests::it_adds_two stdout ----
thread 'tests::it_adds_two' panicked at src/lib.rs:12:9:
assertion `left == right` failed
left: 5
right: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ANCHOR: here
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
a + 3
}
// ANCHOR_END: here
Expand All @@ -10,6 +10,7 @@ mod tests {

#[test]
fn it_adds_two() {
assert_eq!(add_two(2), 4);
let result = add_two(2);
assert_eq!(result, 4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ mod tests {
let result = greeting("Carol");
assert!(
result.contains("Carol"),
"Greeting did not contain name, value was `{}`",
result
"Greeting did not contain name, value was `{result}`"
);
}
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

// ANCHOR: here
#[test]
fn it_works() -> Result<(), String> {
if 2 + 2 == 4 {
let result = add(2, 2);

if result == 4 {
Ok(())
} else {
Err(String::from("two plus two does not equal four"))
}
}
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ $ cargo test
Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4)

running 2 tests
test expensive_test ... ignored
test it_works ... ok
test tests::expensive_test ... ignored
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[test]
#[ignore]
fn expensive_test() {
// code that takes an hour to run
// ANCHOR: here
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}

#[test]
#[ignore]
fn expensive_test() {
// code that takes an hour to run
}
}
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
internal_adder(a, 2)
}

fn internal_adder(a: i32, b: i32) -> i32 {
a + b
fn internal_adder(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
Expand All @@ -12,6 +12,7 @@ mod tests {

#[test]
fn internal() {
assert_eq!(4, internal_adder(2, 2));
let result = internal_adder(2, 2);
assert_eq!(result, 4);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use adder;
use adder::add_two;

#[test]
fn it_adds_two() {
assert_eq!(4, adder::add_two(2));
let result = add_two(2);
assert_eq!(result, 4);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub fn add_two(a: i32) -> i32 {
pub fn add_two(a: usize) -> usize {
internal_adder(a, 2)
}

fn internal_adder(a: i32, b: i32) -> i32 {
a + b
fn internal_adder(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
Expand All @@ -12,6 +12,7 @@ mod tests {

#[test]
fn internal() {
assert_eq!(4, internal_adder(2, 2));
let result = internal_adder(2, 2);
assert_eq!(result, 4);
}
}
Loading
Loading