Skip to content

Commit a786ec4

Browse files
committed
Use v1.58 captured ident formatting in examples
Per #3047, use captured identifiers instead of the positional ones for some examples, e.g. ```diff - println!("Worker {} got a job; executing.", id); + println!("Worker {id} got a job; executing."); ```
1 parent 3dca2fc commit a786ec4

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
}

0 commit comments

Comments
 (0)