Skip to content

Commit 9622474

Browse files
authored
Merge pull request #3048 from nyurik/format-ident
Use v1.58 captured ident formatting in examples
2 parents f84626d + a786ec4 commit 9622474

File tree

15 files changed

+21
-21
lines changed
  • listings
    • ch04-understanding-ownership
    • ch06-enums-and-pattern-matching
      • no-listing-09-variable-in-pattern/src
      • no-listing-13-count-and-announce-match/src
      • no-listing-14-count-and-announce-if-let-else/src
    • ch11-writing-automated-tests/no-listing-05-greeter/src
    • ch16-fearless-concurrency
    • ch18-patterns-and-matching
  • redirects

15 files changed

+21
-21
lines changed

listings/ch04-understanding-ownership/listing-04-05/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn main() {
33

44
let (s2, len) = calculate_length(s1);
55

6-
println!("The length of '{}' is {}.", s2, len);
6+
println!("The length of '{s2}' is {len}.");
77
}
88

99
fn calculate_length(s: String) -> (String, usize) {

listings/ch04-understanding-ownership/no-listing-05-clone/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ fn main() {
33
let s1 = String::from("hello");
44
let s2 = s1.clone();
55

6-
println!("s1 = {}, s2 = {}", s1, s2);
6+
println!("s1 = {s1}, s2 = {s2}");
77
// ANCHOR_END: here
88
}

listings/ch04-understanding-ownership/no-listing-06-copy/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ fn main() {
33
let x = 5;
44
let y = x;
55

6-
println!("x = {}, y = {}", x, y);
6+
println!("x = {x}, y = {y}");
77
// ANCHOR_END: here
88
}

listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fn main() {
66
let len = calculate_length(&s1);
77
// ANCHOR_END: here
88

9-
println!("The length of '{}' is {}.", s1, len);
9+
println!("The length of '{s1}' is {len}.");
1010
}
1111

1212
fn calculate_length(s: &String) -> usize {

listings/ch04-understanding-ownership/no-listing-08-reference-with-annotations/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn main() {
33

44
let len = calculate_length(&s1);
55

6-
println!("The length of '{}' is {}.", s1, len);
6+
println!("The length of '{s1}' is {len}.");
77
}
88

99
// ANCHOR: here

listings/ch06-enums-and-pattern-matching/no-listing-09-variable-in-pattern/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn value_in_cents(coin: Coin) -> u8 {
1919
Coin::Nickel => 5,
2020
Coin::Dime => 10,
2121
Coin::Quarter(state) => {
22-
println!("State quarter from {:?}!", state);
22+
println!("State quarter from {state:?}!");
2323
25
2424
}
2525
}

listings/ch06-enums-and-pattern-matching/no-listing-13-count-and-announce-match/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
// ANCHOR: here
1818
let mut count = 0;
1919
match coin {
20-
Coin::Quarter(state) => println!("State quarter from {:?}!", state),
20+
Coin::Quarter(state) => println!("State quarter from {state:?}!"),
2121
_ => count += 1,
2222
}
2323
// ANCHOR_END: here

listings/ch06-enums-and-pattern-matching/no-listing-14-count-and-announce-if-let-else/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
// ANCHOR: here
1818
let mut count = 0;
1919
if let Coin::Quarter(state) = coin {
20-
println!("State quarter from {:?}!", state);
20+
println!("State quarter from {state:?}!");
2121
} else {
2222
count += 1;
2323
}

listings/ch11-writing-automated-tests/no-listing-05-greeter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub fn greeting(name: &str) -> String {
2-
format!("Hello {}!", name)
2+
format!("Hello {name}!")
33
}
44

55
#[cfg(test)]

listings/ch16-fearless-concurrency/listing-16-01/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::time::Duration;
44
fn main() {
55
thread::spawn(|| {
66
for i in 1..10 {
7-
println!("hi number {} from the spawned thread!", i);
7+
println!("hi number {i} from the spawned thread!");
88
thread::sleep(Duration::from_millis(1));
99
}
1010
});
1111

1212
for i in 1..5 {
13-
println!("hi number {} from the main thread!", i);
13+
println!("hi number {i} from the main thread!");
1414
thread::sleep(Duration::from_millis(1));
1515
}
1616
}

listings/ch16-fearless-concurrency/listing-16-02/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::time::Duration;
44
fn main() {
55
let handle = thread::spawn(|| {
66
for i in 1..10 {
7-
println!("hi number {} from the spawned thread!", i);
7+
println!("hi number {i} from the spawned thread!");
88
thread::sleep(Duration::from_millis(1));
99
}
1010
});
1111

1212
for i in 1..5 {
13-
println!("hi number {} from the main thread!", i);
13+
println!("hi number {i} from the main thread!");
1414
thread::sleep(Duration::from_millis(1));
1515
}
1616

listings/ch16-fearless-concurrency/no-listing-01-join-too-early/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use std::time::Duration;
44
fn main() {
55
let handle = thread::spawn(|| {
66
for i in 1..10 {
7-
println!("hi number {} from the spawned thread!", i);
7+
println!("hi number {i} from the spawned thread!");
88
thread::sleep(Duration::from_millis(1));
99
}
1010
});
1111

1212
handle.join().unwrap();
1313

1414
for i in 1..5 {
15-
println!("hi number {} from the main thread!", i);
15+
println!("hi number {i} from the main thread!");
1616
thread::sleep(Duration::from_millis(1));
1717
}
1818
}

listings/ch18-patterns-and-matching/listing-18-11/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ fn main() {
66
match x {
77
Some(50) => println!("Got 50"),
88
Some(y) => println!("Matched, y = {y}"),
9-
_ => println!("Default case, x = {:?}", x),
9+
_ => println!("Default case, x = {x:?}"),
1010
}
1111

12-
println!("at the end: x = {:?}, y = {y}", x);
12+
println!("at the end: x = {x:?}, y = {y}");
1313
// ANCHOR_END: here
1414
}

listings/ch18-patterns-and-matching/listing-18-27/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
match x {
66
Some(50) => println!("Got 50"),
77
Some(n) if n == y => println!("Matched, n = {n}"),
8-
_ => println!("Default case, x = {:?}", x),
8+
_ => println!("Default case, x = {x:?}"),
99
}
1010

1111
println!("at the end: x = {:?}, y = {y}", x);

redirects/loops.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ loop {
1414
1515
let mut number = 3;
1616
while number != 0 {
17-
println!("{}!", number);
17+
println!("{number}!");
1818
number = number - 1;
1919
}
2020
2121
let a = [10, 20, 30, 40, 50];
2222
for element in a.iter() {
23-
println!("the value is: {}", element);
23+
println!("the value is: {element}");
2424
}
2525
```
2626

2727
---
2828

2929
You can find the latest version of this information
30-
[here](ch03-05-control-flow.html#repetition-with-loops).
30+
[here](ch03-05-control-flow.html#repetition-with-loops).

0 commit comments

Comments
 (0)