Inline all format arguments

The inlined format arguments are a bit easier to understand,
especially for those familiar with the other languages (python, js).
This commit is contained in:
Yuri Astrakhan 2022-10-13 15:01:58 -04:00
parent 3dca2fc50b
commit f55ac5d8fa
104 changed files with 139 additions and 139 deletions

View File

@ -2,7 +2,7 @@
name = "rust-book"
version = "0.0.1"
description = "The Rust Book"
edition = "2018"
edition = "2021"
[[bin]]
name = "concat_chapters"

View File

@ -6,4 +6,4 @@ fn main() {
// do stuff with s
} // this scope is now over, and s is no longer valid
// ANCHOR_END: here
}
}

View File

@ -14,10 +14,10 @@ fn main() {
// special happens.
fn takes_ownership(some_string: String) { // some_string comes into scope
println!("{}", some_string);
println!("{some_string}");
} // Here, some_string goes out of scope and `drop` is called. The backing
// memory is freed.
fn makes_copy(some_integer: i32) { // some_integer comes into scope
println!("{}", some_integer);
println!("{some_integer}");
} // Here, some_integer goes out of scope. Nothing special happens.

View File

@ -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) {

View File

@ -4,6 +4,6 @@ fn main() {
s.push_str(", world!"); // push_str() appends a literal to a String
println!("{}", s); // This will print `hello, world!`
// ANCHOR_END: here
println!("{s}"); // This will print `hello, world!`
// ANCHOR_END: here
}

View File

@ -3,6 +3,6 @@ fn main() {
let s1 = String::from("hello");
let s2 = s1;
println!("{}, world!", s1);
println!("{s1}, world!");
// ANCHOR_END: here
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -4,10 +4,10 @@ fn main() {
let r1 = &s; // no problem
let r2 = &s; // no problem
println!("{} and {}", r1, r2);
println!("{r1} and {r2}");
// variables r1 and r2 will not be used after this point
let r3 = &mut s; // no problem
println!("{}", r3);
println!("{r3}");
// ANCHOR_END: here
}

View File

@ -18,6 +18,6 @@ fn main() {
s.clear(); // error!
println!("the first word is: {}", word);
println!("the first word is: {word}");
}
// ANCHOR_END: here

View File

@ -10,5 +10,5 @@ fn main() {
height: 50,
};
println!("rect1 is {:?}", rect1);
println!("rect1 is {rect1:?}");
}

View File

@ -10,5 +10,5 @@ fn main() {
height: 50,
};
println!("rect1 is {:#?}", rect1);
println!("rect1 is {rect1:#?}");
}

View File

@ -2,7 +2,7 @@ fn main() {
// ANCHOR: here
let config_max = Some(3u8);
match config_max {
Some(max) => println!("The maximum is configured to be {}", max),
Some(max) => println!("The maximum is configured to be {max}"),
_ => (),
}
// ANCHOR_END: here

View File

@ -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
}
}

View File

@ -2,7 +2,7 @@ fn main() {
// ANCHOR: here
let config_max = Some(3u8);
if let Some(max) = config_max {
println!("The maximum is configured to be {}", max);
println!("The maximum is configured to be {max}");
}
// ANCHOR_END: here
}

View File

@ -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

View File

@ -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;
}

View File

@ -4,5 +4,5 @@ pub mod garden;
fn main() {
let plant = Asparagus {};
println!("I'm growing {:?}!", plant);
println!("I'm growing {plant:?}!");
}

View File

@ -7,6 +7,6 @@ fn main() {
scores.insert(String::from("Blue"), 10);
scores.insert(String::from("Blue"), 25);
println!("{:?}", scores);
println!("{scores:?}");
// ANCHOR_END: here
}

View File

@ -8,6 +8,6 @@ fn main() {
scores.entry(String::from("Yellow")).or_insert(50);
scores.entry(String::from("Blue")).or_insert(50);
println!("{:?}", scores);
println!("{scores:?}");
// ANCHOR_END: here
}

View File

@ -11,6 +11,6 @@ fn main() {
*count += 1;
}
println!("{:?}", map);
println!("{map:?}");
// ANCHOR_END: here
}

View File

@ -5,6 +5,6 @@ fn main() {
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {:?}", error),
Err(error) => panic!("Problem opening the file: {error:?}"),
};
}

View File

@ -9,10 +9,10 @@ fn main() {
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
Ok(fc) => fc,
Err(e) => panic!("Problem creating the file: {:?}", e),
Err(e) => panic!("Problem creating the file: {e:?}"),
},
other_error => {
panic!("Problem opening the file: {:?}", other_error);
panic!("Problem opening the file: {other_error:?}");
}
},
};

View File

@ -10,7 +10,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}
Guess { value }

View File

@ -10,7 +10,7 @@ fn main() {
}
}
println!("The largest number is {}", largest);
println!("The largest number is {largest}");
// ANCHOR_END: here
assert_eq!(*largest, 100);
// ANCHOR: here

View File

@ -9,7 +9,7 @@ fn main() {
}
}
println!("The largest number is {}", largest);
println!("The largest number is {largest}");
let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];
@ -21,5 +21,5 @@ fn main() {
}
}
println!("The largest number is {}", largest);
println!("The largest number is {largest}");
}

View File

@ -15,7 +15,7 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 100);
// ANCHOR: here
@ -23,7 +23,7 @@ fn main() {
let number_list = vec![102, 34, 6000, 89, 54, 2, 43, 8];
let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 6000);
// ANCHOR: here

View File

@ -27,7 +27,7 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest_i32(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
// ANCHOR_END: here
assert_eq!(*result, 100);
// ANCHOR: here
@ -35,7 +35,7 @@ fn main() {
let char_list = vec!['y', 'm', 'a', 'q'];
let result = largest_char(&char_list);
println!("The largest char is {}", result);
println!("The largest char is {result}");
// ANCHOR_END: here
assert_eq!(*result, 'y');
// ANCHOR: here

View File

@ -14,10 +14,10 @@ fn main() {
let number_list = vec![34, 50, 25, 100, 65];
let result = largest(&number_list);
println!("The largest number is {}", result);
println!("The largest number is {result}");
let char_list = vec!['y', 'm', 'a', 'q'];
let result = largest(&char_list);
println!("The largest char is {}", result);
println!("The largest char is {result}");
}

View File

@ -6,5 +6,5 @@ fn main() {
r = &x;
}
println!("r: {}", r);
println!("r: {r}");
}

View File

@ -6,5 +6,5 @@ fn main() {
r = &x; // | |
} // -+ |
// |
println!("r: {}", r); // |
println!("r: {r}"); // |
} // ---------+

View File

@ -3,6 +3,6 @@ fn main() {
// |
let r = &x; // --+-- 'a |
// | |
println!("r: {}", r); // | |
println!("r: {r}"); // | |
// --+ |
} // ----------+

View File

@ -3,5 +3,5 @@ fn main() {
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}

View File

@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR: here

View File

@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR: here

View File

@ -5,7 +5,7 @@ fn main() {
{
let string2 = String::from("xyz");
let result = longest(string1.as_str(), string2.as_str());
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
}
// ANCHOR_END: here

View File

@ -7,8 +7,8 @@ error[E0597]: `string2` does not live long enough
| ^^^^^^^^^^^^^^^^ borrowed value does not live long enough
7 | }
| - `string2` dropped here while still borrowed
8 | println!("The longest string is {}", result);
| ------ borrow later used here
8 | println!("The longest string is {result}");
| ------ borrow later used here
For more information about this error, try `rustc --explain E0597`.
error: could not compile `chapter10` due to previous error

View File

@ -6,7 +6,7 @@ fn main() {
let string2 = String::from("xyz");
result = longest(string1.as_str(), string2.as_str());
}
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR_END: here

View File

@ -3,7 +3,7 @@ fn main() {
let string2 = "efghijklmnopqrstuvwxyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR: here

View File

@ -3,7 +3,7 @@ fn main() {
let string2 = "xyz";
let result = longest(string1.as_str(), string2);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR: here

View File

@ -13,7 +13,7 @@ impl<'a> ImportantExcerpt<'a> {
// ANCHOR: 3rd
impl<'a> ImportantExcerpt<'a> {
fn announce_and_return_part(&self, announcement: &str) -> &str {
println!("Attention please: {}", announcement);
println!("Attention please: {announcement}");
self.part
}
}

View File

@ -7,7 +7,7 @@ fn main() {
string2,
"Today is someone's birthday!",
);
println!("The longest string is {}", result);
println!("The longest string is {result}");
}
// ANCHOR: here
@ -21,7 +21,7 @@ fn longest_with_an_announcement<'a, T>(
where
T: Display,
{
println!("Announcement! {}", ann);
println!("Announcement! {ann}");
if x.len() > y.len() {
x
} else {

View File

@ -5,7 +5,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}
Guess { value }

View File

@ -1,5 +1,5 @@
fn prints_and_returns_10(a: i32) -> i32 {
println!("I got the value {}", a);
println!("I got the value {a}");
10
}

View File

@ -1,5 +1,5 @@
pub fn greeting(name: &str) -> String {
format!("Hello {}!", name)
format!("Hello {name}!")
}
#[cfg(test)]

View File

@ -7,7 +7,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}
Guess { value }

View File

@ -1,5 +1,5 @@
pub fn prints_and_returns_10(a: i32) -> i32 {
println!("I got the value {}", a);
println!("I got the value {a}");
10
}

View File

@ -6,6 +6,6 @@ fn main() {
let query = &args[1];
let file_path = &args[2];
println!("Searching for {}", query);
println!("In file {}", file_path);
println!("Searching for {query}");
println!("In file {file_path}");
}

View File

@ -6,6 +6,6 @@ fn main() {
let query = &args[1];
let file_path = &args[2];
println!("Searching for {}", query);
println!("In file {}", file_path);
println!("Searching for {query}");
println!("In file {file_path}");
}

View File

@ -10,9 +10,9 @@ fn main() {
let query = &args[1];
let file_path = &args[2];
println!("Searching for {}", query);
println!("Searching for {query}");
// ANCHOR: here
println!("In file {}", file_path);
println!("In file {file_path}");
let contents = fs::read_to_string(file_path)
.expect("Should have been able to read the file");

View File

@ -10,8 +10,8 @@ fn main() {
// --snip--
// ANCHOR_END: here
println!("Searching for {}", query);
println!("In file {}", file_path);
println!("Searching for {query}");
println!("In file {file_path}");
let contents = fs::read_to_string(file_path)
.expect("Should have been able to read the file");

View File

@ -1,10 +1,10 @@
fn main() {
let list = vec![1, 2, 3];
println!("Before defining closure: {:?}", list);
println!("Before defining closure: {list:?}");
let only_borrows = || println!("From closure: {:?}", list);
let only_borrows = || println!("From closure: {list:?}");
println!("Before calling closure: {:?}", list);
println!("Before calling closure: {list:?}");
only_borrows();
println!("After calling closure: {:?}", list);
println!("After calling closure: {list:?}");
}

View File

@ -1,9 +1,9 @@
fn main() {
let mut list = vec![1, 2, 3];
println!("Before defining closure: {:?}", list);
println!("Before defining closure: {list:?}");
let mut borrows_mutably = || list.push(7);
borrows_mutably();
println!("After calling closure: {:?}", list);
println!("After calling closure: {list:?}");
}

View File

@ -2,9 +2,9 @@ use std::thread;
fn main() {
let list = vec![1, 2, 3];
println!("Before defining closure: {:?}", list);
println!("Before defining closure: {list:?}");
thread::spawn(move || println!("From thread: {:?}", list))
thread::spawn(move || println!("From thread: {list:?}"))
.join()
.unwrap();
}

View File

@ -12,5 +12,5 @@ fn main() {
];
list.sort_by_key(|r| r.width);
println!("{:#?}", list);
println!("{list:#?}");
}

View File

@ -18,5 +18,5 @@ fn main() {
sort_operations.push(value);
r.width
});
println!("{:#?}", list);
println!("{list:#?}");
}

View File

@ -16,5 +16,5 @@ fn main() {
num_sort_operations += 1;
r.width
});
println!("{:#?}, sorted in {num_sort_operations} operations", list);
println!("{list:#?}, sorted in {num_sort_operations} operations");
}

View File

@ -5,7 +5,7 @@ fn main() {
let v1_iter = v1.iter();
for val in v1_iter {
println!("Got: {}", val);
println!("Got: {val}");
}
// ANCHOR_END: here
}

View File

@ -1,4 +1,4 @@
fn main() {
let b = Box::new(5);
println!("b = {}", b);
println!("b = {b}");
}

View File

@ -18,7 +18,7 @@ fn main() {
*value.borrow_mut() += 10;
println!("a after = {:?}", a);
println!("b after = {:?}", b);
println!("c after = {:?}", c);
println!("a after = {a:?}");
println!("b after = {b:?}");
println!("c after = {c:?}");
}

View File

@ -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));
}
}

View File

@ -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));
}

View File

@ -5,15 +5,15 @@ error[E0373]: closure may outlive the current function, but it borrows `v`, whic
|
6 | let handle = thread::spawn(|| {
| ^^ may outlive borrowed value `v`
7 | println!("Here's a vector: {:?}", v);
| - `v` is borrowed here
7 | println!("Here's a vector: {v:?}");
| - `v` is borrowed here
|
note: function requires argument type to outlive `'static`
--> src/main.rs:6:18
|
6 | let handle = thread::spawn(|| {
| __________________^
7 | | println!("Here's a vector: {:?}", v);
7 | | println!("Here's a vector: {v:?}");
8 | | });
| |______^
help: to force the closure to take ownership of `v` (and any other referenced variables), use the `move` keyword

View File

@ -4,7 +4,7 @@ fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(|| {
println!("Here's a vector: {:?}", v);
println!("Here's a vector: {v:?}");
});
handle.join().unwrap();

View File

@ -4,7 +4,7 @@ fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(|| {
println!("Here's a vector: {:?}", v);
println!("Here's a vector: {v:?}");
});
drop(v); // oh no!

View File

@ -4,7 +4,7 @@ fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(move || {
println!("Here's a vector: {:?}", v);
println!("Here's a vector: {v:?}");
});
handle.join().unwrap();

View File

@ -10,5 +10,5 @@ fn main() {
});
let received = rx.recv().unwrap();
println!("Got: {}", received);
println!("Got: {received}");
}

View File

@ -7,8 +7,8 @@ error[E0382]: borrow of moved value: `val`
| --- move occurs because `val` has type `String`, which does not implement the `Copy` trait
9 | tx.send(val).unwrap();
| --- value moved here
10 | println!("val is {}", val);
| ^^^ value borrowed here after move
10 | println!("val is {val}");
| ^^^ value borrowed here after move
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

View File

@ -7,9 +7,9 @@ fn main() {
thread::spawn(move || {
let val = String::from("hi");
tx.send(val).unwrap();
println!("val is {}", val);
println!("val is {val}");
});
let received = rx.recv().unwrap();
println!("Got: {}", received);
println!("Got: {received}");
}

View File

@ -20,6 +20,6 @@ fn main() {
});
for received in rx {
println!("Got: {}", received);
println!("Got: {received}");
}
}

View File

@ -38,7 +38,7 @@ fn main() {
});
for received in rx {
println!("Got: {}", received);
println!("Got: {received}");
}
// --snip--

View File

@ -8,5 +8,5 @@ fn main() {
*num = 6;
}
println!("m = {:?}", m);
println!("m = {m:?}");
}

View File

@ -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));
}
}

View File

@ -8,8 +8,8 @@ error[E0382]: use of moved value: `v`
5 |
6 | let handle = thread::spawn(move || {
| ------- value moved into closure here
7 | println!("Here's a vector: {:?}", v);
| - variable moved due to use in closure
7 | println!("Here's a vector: {v:?}");
| - variable moved due to use in closure
...
10 | drop(v); // oh no!
| ^ value used here after move

View File

@ -4,7 +4,7 @@ fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(move || {
println!("Here's a vector: {:?}", v);
println!("Here's a vector: {v:?}");
});
drop(v); // oh no!

View File

@ -7,7 +7,7 @@ fn main() {
stack.push(3);
while let Some(top) = stack.pop() {
println!("{}", top);
println!("{top}");
}
// ANCHOR_END: here
}

View File

@ -3,7 +3,7 @@ fn main() {
let v = vec!['a', 'b', 'c'];
for (index, value) in v.iter().enumerate() {
println!("{} is at index {}", value, index);
println!("{value} is at index {index}");
}
// ANCHOR_END: here
}

View File

@ -1,5 +1,5 @@
fn print_coordinates(&(x, y): &(i32, i32)) {
println!("Current location: ({}, {})", x, y);
println!("Current location: ({x}, {y})");
}
fn main() {

View File

@ -2,7 +2,7 @@ fn main() {
let some_option_value: Option<i32> = None;
// ANCHOR: here
if let Some(x) = some_option_value {
println!("{}", x);
println!("{x}");
}
// ANCHOR_END: here
}

View File

@ -1,7 +1,7 @@
fn main() {
// ANCHOR: here
if let x = 5 {
println!("{}", x);
println!("{x}");
};
// ANCHOR_END: here
}

View File

@ -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
}

View File

@ -19,7 +19,7 @@ fn main() {
println!("Text message: {text}");
}
Message::ChangeColor(r, g, b) => {
println!("Change the color to red {r}, green {g}, and blue {b}",)
println!("Change the color to red {r}, green {g}, and blue {b}")
}
}
}

View File

@ -1,5 +1,5 @@
fn foo(_: i32, y: i32) {
println!("This code only uses the y parameter: {}", y);
println!("This code only uses the y parameter: {y}");
}
fn main() {

View File

@ -12,6 +12,6 @@ fn main() {
}
}
println!("setting is {:?}", setting_value);
println!("setting is {setting_value:?}");
// ANCHOR_END: here
}

View File

@ -6,6 +6,6 @@ fn main() {
println!("found a string");
}
println!("{:?}", s);
println!("{s:?}");
// ANCHOR_END: here
}

View File

@ -6,6 +6,6 @@ fn main() {
println!("found a string");
}
println!("{:?}", s);
println!("{s:?}");
// ANCHOR_END: here
}

View File

@ -9,7 +9,7 @@ fn main() {
let origin = Point { x: 0, y: 0, z: 0 };
match origin {
Point { x, .. } => println!("x is {}", x),
Point { x, .. } => println!("x is {x}"),
}
// ANCHOR_END: here
}

View File

@ -3,7 +3,7 @@ fn main() {
match numbers {
(.., second, ..) => {
println!("Some numbers: {}", second)
println!("Some numbers: {second}")
},
}
}

View File

@ -3,8 +3,8 @@ fn main() {
let num = Some(4);
match num {
Some(x) if x % 2 == 0 => println!("The number {} is even", x),
Some(x) => println!("The number {} is odd", x),
Some(x) if x % 2 == 0 => println!("The number {x} is even"),
Some(x) => println!("The number {x} is odd"),
None => (),
}
// ANCHOR_END: here

View File

@ -5,8 +5,8 @@ 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);
println!("at the end: x = {x:?}, y = {y}");
}

View File

@ -9,11 +9,11 @@ fn main() {
match msg {
Message::Hello {
id: id_variable @ 3..=7,
} => println!("Found an id in range: {}", id_variable),
} => println!("Found an id in range: {id_variable}"),
Message::Hello { id: 10..=12 } => {
println!("Found an id in another range")
}
Message::Hello { id } => println!("Found some other id: {}", id),
Message::Hello { id } => println!("Found some other id: {id}"),
}
// ANCHOR_END: here
}

View File

@ -1,5 +1,5 @@
static HELLO_WORLD: &str = "Hello, world!";
fn main() {
println!("name is: {}", HELLO_WORLD);
println!("name is: {HELLO_WORLD}");
}

View File

@ -10,6 +10,6 @@ fn main() {
add_to_count(3);
unsafe {
println!("COUNTER: {}", COUNTER);
println!("COUNTER: {COUNTER}");
}
}

View File

@ -7,7 +7,7 @@ trait OutlinePrint: fmt::Display {
let len = output.len();
println!("{}", "*".repeat(len + 4));
println!("*{}*", " ".repeat(len + 2));
println!("* {} *", output);
println!("* {output} *");
println!("*{}*", " ".repeat(len + 2));
println!("{}", "*".repeat(len + 4));
}

View File

@ -10,5 +10,5 @@ impl fmt::Display for Wrapper {
fn main() {
let w = Wrapper(vec![String::from("hello"), String::from("world")]);
println!("w = {}", w);
println!("w = {w}");
}

View File

@ -9,5 +9,5 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
fn main() {
let answer = do_twice(add_one, 5);
println!("The answer is: {}", answer);
println!("The answer is: {answer}");
}

View File

@ -6,7 +6,7 @@ trait OutlinePrint: fmt::Display {
let len = output.len();
println!("{}", "*".repeat(len + 4));
println!("*{}*", " ".repeat(len + 2));
println!("* {} *", output);
println!("* {output} *");
println!("*{}*", " ".repeat(len + 2));
println!("{}", "*".repeat(len + 4));
}

View File

@ -4,7 +4,7 @@ trait OutlinePrint: fmt::Display {
let len = output.len();
println!("{}", "*".repeat(len + 4));
println!("*{}*", " ".repeat(len + 2));
println!("* {} *", output);
println!("* {output} *");
println!("*{}*", " ".repeat(len + 2));
println!("{}", "*".repeat(len + 4));
}

Some files were not shown because too many files have changed in this diff Show More