Compare commits

...

54 Commits

Author SHA1 Message Date
Ahmed Radwan 0dfabf1d91
Merge 45797e422a into d207d894cc 2024-04-25 11:32:06 -06:00
Chris Krycho d207d894cc
Merge pull request #3898 from rust-lang/chriskrycho/crab-pincers
Ch. 2: intentionally use `{}` at first
2024-04-19 13:48:19 -06:00
Chris Krycho 0b4e00345c
Merge pull request #3897 from nyurik/redirect-lints
Inline fmt lints for `redirects/`
2024-04-19 13:48:13 -06:00
Chris Krycho 502d012cab Ch. 2: intentionally use `{}` at first
This supports the prose in the guessing game tutorial, which uses this
as a way of teaching where you can do `{foo}` and where you cannot.
2024-04-19 13:42:05 -06:00
Yuri Astrakhan c13271897d Inline fmt lints for `redirects/`
I couldn't find any documentation of how `redirects/` dir is being used,
but fixed inlined format args for consistency
2024-04-19 15:40:41 -04:00
Chris Krycho 8a79f3e15d
Merge pull request #3287 from bravequickcleverfibreyarn/listing-12-02
ch12-03: `expect` is not used multitude times by this chapter
2024-04-19 13:36:49 -06:00
Chris Krycho 62516ee9e3
Merge pull request #3896 from nyurik/inline-fmt-arg
Inline format args to `tools/src`
2024-04-19 13:36:10 -06:00
Chris Krycho f3d9661aff
Merge pull request #3290 from agotsis/closure-grammar
Improve awkward phrasing around the kinds of closures
2024-04-19 13:35:36 -06:00
Chris Krycho 54726034c5
Ch. 12.3: be clearer about how `expect` was used 2024-04-19 13:35:31 -06:00
Chris Krycho 8264d69aa6
Ch. 13: `unwrap_or_else` takes all three kinds of closures 2024-04-19 13:31:53 -06:00
Yuri Astrakhan c5211edeec Apply clippy::uninlined_format_args fix 2024-04-19 15:20:22 -04:00
Chris Krycho 0bcde15346
Merge pull request #3890 from rust-lang/push-vmxrspyskulq
Ch. 14: clarify workspace dependency reuse
2024-04-19 13:19:52 -06:00
Chris Krycho 50149d92e0
Merge pull request #3281 from thedumbsloth/function_name_fix_7.3
Edit on line no. 153. Replaced fn add_to_waitlist with fn eat_at_restaurant.
2024-04-19 13:12:00 -06:00
Chris Krycho 874d9a2131
Merge pull request #3895 from rust-lang/chriskrycho/vhb
Ch. 2: less ambiguity about numbers
2024-04-19 13:06:51 -06:00
Chris Krycho 523d960984 Merge `main` into `chriskrycho/vhb` 2024-04-19 13:02:06 -06:00
Chris Krycho 0729f34edc Ch. 2: Further simplify language about numbers 2024-04-19 12:56:58 -06:00
Chris Krycho f9d4e058a9
Merge pull request #3363 from vinsburg/patch-4
Clarified first slices paragraph
2024-04-19 12:51:38 -06:00
Chris Krycho 82df41e8bd Ch. 4: include link forward to collections
Remove the additional, extraneous info from the Ch. 4. section 3 intro.
2024-04-19 12:49:38 -06:00
Chris Krycho 162d540045
Merge pull request #3385 from nyurik/inlinefmt2
Inline all format arguments
2024-04-19 12:03:47 -06:00
Chris Krycho 6196a0ab45 Merge `main` into `nyurik:inlinefmt2` 2024-04-19 11:57:29 -06:00
Chris Krycho 96224742f3
Merge pull request #3048 from nyurik/format-ident
Use v1.58 captured ident formatting in examples
2024-04-19 11:49:12 -06:00
Chris Krycho f84626dbe0
Merge pull request #3894 from rust-lang/revert-3397-ch18-03-pattern-syntax.md
Revert "ch18-03: Guarded match arm exhaustivness clarification"
2024-04-18 16:34:49 -06:00
Chris Krycho d737e4db6b
Revert "ch18-03: Guarded match arm exhaustivness clarification" 2024-04-18 16:14:25 -06:00
Chris Krycho 8e5e4ae8df
Merge pull request #3893 from rust-lang/push-zwrsqqxunozz
Ch. 18: further clarify about irrefutable patterns
2024-04-18 14:00:38 -06:00
Chris Krycho 0b869eecc8 Ch. 18: further clarify about irrefutable patterns 2024-04-18 13:57:55 -06:00
Chris Krycho 976b2d812d
Merge pull request #3381 from bravequickcleverfibreyarn/ch18-02-refutability.md
ch18-02: Minor corrections
2024-04-18 13:55:32 -06:00
Chris Krycho 6d8afd25f0
Merge pull request #3217 from frankplow/error-handling-uses
Make style of listings 9-7 and 9-8 consistent with 9-6
2024-04-18 13:44:41 -06:00
Chris Krycho 49157edbca
Merge pull request #3397 from bravequickcleverfibreyarn/ch18-03-pattern-syntax.md
ch18-03: Guarded match arm exhaustivness clarification
2024-04-18 12:28:53 -06:00
Chris Krycho 18effd3176
Merge pull request #3284 from bravequickcleverfibreyarn/ch11-03-test-organization.md
ch11-03: Unnecessary import removal
2024-04-18 12:13:52 -06:00
Chris Krycho 076420ce20 Ch. 11: `use` scope tweak 2024-04-18 12:08:28 -06:00
Chris Krycho afe19ddb7e
Merge pull request #3394 from MarijnRitzen/patch-3
Update ch20-01-single-threaded.md
2024-04-17 17:17:06 -06:00
Chris Krycho d68ddcc4d5
Ch. 20: shorter version of corrected listing 2024-04-17 17:16:59 -06:00
Chris Krycho 0eb2257923
Merge pull request #3418 from krishnakumarg1984/kg/add_appendixe_url
In Appendix D, adds hyperlink to Appendix E
2024-04-17 17:11:02 -06:00
Chris Krycho ba4b237a2f
Merge pull request #3433 from SilkovAlexander/typo_to_trait
Chapter 13-03 fixed Iterator 'type' to 'trait'
2024-04-17 17:07:52 -06:00
Chris Krycho 1221096717 Ch. 14: clarify workspace dependency reuse
Fixes #3141
2024-04-17 12:35:06 -06:00
Yuri Astrakhan a786ec4a2b Use v1.58 captured ident formatting in examples
Per https://github.com/rust-lang/book/issues/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.");
```
2023-10-30 11:54:45 -04:00
Yuri Astrakhan f55ac5d8fa Inline all format arguments
The inlined format arguments are a bit easier to understand,
especially for those familiar with the other languages (python, js).
2023-10-30 11:54:36 -04:00
Ahmed Radwan 45797e422a
fix-2058 remove trailing flush 2023-01-01 18:27:43 +02:00
Ahmed Radwan 1fcda61606
fix-2058 remove trailing flush 2023-01-01 18:24:26 +02:00
SilkovAlexander 72b2348d78 Fixed a typo 2022-11-19 20:10:06 +03:00
Krishnakumar Gopalakrishnan 64af4ed516 In Appendix D, adds hyperlink to Appendix E 2022-11-09 14:03:15 +00:00
JirCep 7f495192be ignore,does_not_compile 2022-10-22 23:00:13 +02:00
JirCep e4881ec331 print! for both 2022-10-22 22:47:00 +02:00
JirCep 3e2e5214f4 Guarded match arm exhaustivness clarification 2022-10-22 22:38:27 +02:00
Marijn 7c9680b286
Update ch20-01-single-threaded.md
Listing 20-8 is the html file
2022-10-20 15:05:57 +02:00
JirCep d78fe8764a Minor corrections
Irrefutable pattern receives warning, refutable error, when used unexpectedly.
2022-10-08 22:02:53 +02:00
Amit Weisbord 3a8ff9bdd2
Fix broken url 2022-09-27 15:22:13 +03:00
Amit Weisbord 7b109240d2
Clarified collection in slice definition
Noticed the slice definition in the first paragraph relies on the reader recalling:
* what collections are
* that the reference page ended stating slices are a kind of reference

I think the first paragraph should be more clear to someone who lands on it and isn't reading the rest of the documentation ATM.
2022-09-27 10:14:41 +03:00
Víctor Hernández 3ebc3b285f
Update ch02-00-guessing-game-tutorial.md
The example code converts the input into a whole number. Replace the text "convert the String the program reads as input into a real number type" to "an actual number type" as the word real might be understood as one of the number categories instead as a synonym to "actual".
2022-09-01 14:22:21 +02:00
Alex Gotsis 6c63c46817 Improve awkward phrasing around the kinds of closures 2022-08-05 00:56:52 -07:00
JirCep 15616bc09b `expect` is not used multitude times by this chapter 2022-08-03 22:14:44 +02:00
JirCep 0e9980e429 Unnecessary import removal
As per my observations crate being subject to integration tests is available for qualified reference without importing it with `use`.
2022-07-30 14:38:08 +02:00
Sanjyoti b260469985
Edit on line no. 153.
Edit on line no. 153. 

The adding of pub keyword to mod hosting and fn add_to_waitlist enables us to use the absolute and relative paths in the fn eat_at_restaurant according to the code specified in listing 7-7.
2022-07-27 20:10:36 +05:30
Frank Plowman f173022b70 make style of listings 9-7 and 9-8 consistent with 9-6 2022-06-13 18:44:10 +01:00
125 changed files with 195 additions and 188 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

@ -25,7 +25,7 @@ fn main() {
// ANCHOR_END: expect
// ANCHOR: print_guess
println!("You guessed: {guess}");
println!("You guessed: {}", guess);
// ANCHOR_END: print_guess
}
// ANCHOR: all

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

@ -9,8 +9,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` (bin "chapter10") due to 1 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

@ -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,6 +1,6 @@
use adder;
use adder::add_two;
#[test]
fn it_adds_two() {
assert_eq!(4, adder::add_two(2));
assert_eq!(4, add_two(2));
}

View File

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

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)
help: consider cloning the value if the performance cost is acceptable

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

View File

@ -21,5 +21,5 @@ fn handle_connection(mut stream: TcpStream) {
.take_while(|line| !line.is_empty())
.collect();
println!("Request: {:#?}", http_request);
println!("Request: {http_request:#?}");
}

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