mirror of https://github.com/rust-lang/book
Merge pull request #3048 from nyurik/format-ident
Use v1.58 captured ident formatting in examples
This commit is contained in:
commit
96224742f3
|
@ -3,7 +3,7 @@ fn main() {
|
|||
|
||||
let (s2, len) = calculate_length(s1);
|
||||
|
||||
println!("The length of '{}' is {}.", s2, len);
|
||||
println!("The length of '{s2}' is {len}.");
|
||||
}
|
||||
|
||||
fn calculate_length(s: String) -> (String, usize) {
|
||||
|
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
let s1 = String::from("hello");
|
||||
let s2 = s1.clone();
|
||||
|
||||
println!("s1 = {}, s2 = {}", s1, s2);
|
||||
println!("s1 = {s1}, s2 = {s2}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
let x = 5;
|
||||
let y = x;
|
||||
|
||||
println!("x = {}, y = {}", x, y);
|
||||
println!("x = {x}, y = {y}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
let len = calculate_length(&s1);
|
||||
// ANCHOR_END: here
|
||||
|
||||
println!("The length of '{}' is {}.", s1, len);
|
||||
println!("The length of '{s1}' is {len}.");
|
||||
}
|
||||
|
||||
fn calculate_length(s: &String) -> usize {
|
||||
|
|
|
@ -3,7 +3,7 @@ fn main() {
|
|||
|
||||
let len = calculate_length(&s1);
|
||||
|
||||
println!("The length of '{}' is {}.", s1, len);
|
||||
println!("The length of '{s1}' is {len}.");
|
||||
}
|
||||
|
||||
// ANCHOR: here
|
||||
|
|
|
@ -19,7 +19,7 @@ fn value_in_cents(coin: Coin) -> u8 {
|
|||
Coin::Nickel => 5,
|
||||
Coin::Dime => 10,
|
||||
Coin::Quarter(state) => {
|
||||
println!("State quarter from {:?}!", state);
|
||||
println!("State quarter from {state:?}!");
|
||||
25
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
// ANCHOR: here
|
||||
let mut count = 0;
|
||||
match coin {
|
||||
Coin::Quarter(state) => println!("State quarter from {:?}!", state),
|
||||
Coin::Quarter(state) => println!("State quarter from {state:?}!"),
|
||||
_ => count += 1,
|
||||
}
|
||||
// ANCHOR_END: here
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
// ANCHOR: here
|
||||
let mut count = 0;
|
||||
if let Coin::Quarter(state) = coin {
|
||||
println!("State quarter from {:?}!", state);
|
||||
println!("State quarter from {state:?}!");
|
||||
} else {
|
||||
count += 1;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub fn greeting(name: &str) -> String {
|
||||
format!("Hello {}!", name)
|
||||
format!("Hello {name}!")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -4,13 +4,13 @@ use std::time::Duration;
|
|||
fn main() {
|
||||
thread::spawn(|| {
|
||||
for i in 1..10 {
|
||||
println!("hi number {} from the spawned thread!", i);
|
||||
println!("hi number {i} from the spawned thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
});
|
||||
|
||||
for i in 1..5 {
|
||||
println!("hi number {} from the main thread!", i);
|
||||
println!("hi number {i} from the main thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,13 @@ use std::time::Duration;
|
|||
fn main() {
|
||||
let handle = thread::spawn(|| {
|
||||
for i in 1..10 {
|
||||
println!("hi number {} from the spawned thread!", i);
|
||||
println!("hi number {i} from the spawned thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
});
|
||||
|
||||
for i in 1..5 {
|
||||
println!("hi number {} from the main thread!", i);
|
||||
println!("hi number {i} from the main thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::time::Duration;
|
|||
fn main() {
|
||||
let handle = thread::spawn(|| {
|
||||
for i in 1..10 {
|
||||
println!("hi number {} from the spawned thread!", i);
|
||||
println!("hi number {i} from the spawned thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ fn main() {
|
|||
handle.join().unwrap();
|
||||
|
||||
for i in 1..5 {
|
||||
println!("hi number {} from the main thread!", i);
|
||||
println!("hi number {i} from the main thread!");
|
||||
thread::sleep(Duration::from_millis(1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ fn main() {
|
|||
match x {
|
||||
Some(50) => println!("Got 50"),
|
||||
Some(y) => println!("Matched, y = {y}"),
|
||||
_ => println!("Default case, x = {:?}", x),
|
||||
_ => println!("Default case, x = {x:?}"),
|
||||
}
|
||||
|
||||
println!("at the end: x = {:?}, y = {y}", x);
|
||||
println!("at the end: x = {x:?}, y = {y}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ fn main() {
|
|||
match x {
|
||||
Some(50) => println!("Got 50"),
|
||||
Some(n) if n == y => println!("Matched, n = {n}"),
|
||||
_ => println!("Default case, x = {:?}", x),
|
||||
_ => println!("Default case, x = {x:?}"),
|
||||
}
|
||||
|
||||
println!("at the end: x = {:?}, y = {y}", x);
|
||||
|
|
|
@ -14,17 +14,17 @@ loop {
|
|||
|
||||
let mut number = 3;
|
||||
while number != 0 {
|
||||
println!("{}!", number);
|
||||
println!("{number}!");
|
||||
number = number - 1;
|
||||
}
|
||||
|
||||
let a = [10, 20, 30, 40, 50];
|
||||
for element in a.iter() {
|
||||
println!("the value is: {}", element);
|
||||
println!("the value is: {element}");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You can find the latest version of this information
|
||||
[here](ch03-05-control-flow.html#repetition-with-loops).
|
||||
[here](ch03-05-control-flow.html#repetition-with-loops).
|
||||
|
|
Loading…
Reference in New Issue