mirror of https://github.com/rust-lang/book
Compare commits
54 Commits
2b0f2fc8a1
...
0dfabf1d91
Author | SHA1 | Date |
---|---|---|
Ahmed Radwan | 0dfabf1d91 | |
Chris Krycho | d207d894cc | |
Chris Krycho | 0b4e00345c | |
Chris Krycho | 502d012cab | |
Yuri Astrakhan | c13271897d | |
Chris Krycho | 8a79f3e15d | |
Chris Krycho | 62516ee9e3 | |
Chris Krycho | f3d9661aff | |
Chris Krycho | 54726034c5 | |
Chris Krycho | 8264d69aa6 | |
Yuri Astrakhan | c5211edeec | |
Chris Krycho | 0bcde15346 | |
Chris Krycho | 50149d92e0 | |
Chris Krycho | 874d9a2131 | |
Chris Krycho | 523d960984 | |
Chris Krycho | 0729f34edc | |
Chris Krycho | f9d4e058a9 | |
Chris Krycho | 82df41e8bd | |
Chris Krycho | 162d540045 | |
Chris Krycho | 6196a0ab45 | |
Chris Krycho | 96224742f3 | |
Chris Krycho | f84626dbe0 | |
Chris Krycho | d737e4db6b | |
Chris Krycho | 8e5e4ae8df | |
Chris Krycho | 0b869eecc8 | |
Chris Krycho | 976b2d812d | |
Chris Krycho | 6d8afd25f0 | |
Chris Krycho | 49157edbca | |
Chris Krycho | 18effd3176 | |
Chris Krycho | 076420ce20 | |
Chris Krycho | afe19ddb7e | |
Chris Krycho | d68ddcc4d5 | |
Chris Krycho | 0eb2257923 | |
Chris Krycho | ba4b237a2f | |
Chris Krycho | 1221096717 | |
Yuri Astrakhan | a786ec4a2b | |
Yuri Astrakhan | f55ac5d8fa | |
Ahmed Radwan | 45797e422a | |
Ahmed Radwan | 1fcda61606 | |
SilkovAlexander | 72b2348d78 | |
Krishnakumar Gopalakrishnan | 64af4ed516 | |
JirCep | 7f495192be | |
JirCep | e4881ec331 | |
JirCep | 3e2e5214f4 | |
Marijn | 7c9680b286 | |
JirCep | d78fe8764a | |
Amit Weisbord | 3a8ff9bdd2 | |
Amit Weisbord | 7b109240d2 | |
Víctor Hernández | 3ebc3b285f | |
Alex Gotsis | 6c63c46817 | |
JirCep | 15616bc09b | |
JirCep | 0e9980e429 | |
Sanjyoti | b260469985 | |
Frank Plowman | f173022b70 |
|
@ -2,7 +2,7 @@
|
|||
name = "rust-book"
|
||||
version = "0.0.1"
|
||||
description = "The Rust Book"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[[bin]]
|
||||
name = "concat_chapters"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,4 +6,4 @@ fn main() {
|
|||
// do stuff with s
|
||||
} // this scope is now over, and s is no longer valid
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
let s1 = String::from("hello");
|
||||
let s2 = s1;
|
||||
|
||||
println!("{}, world!", s1);
|
||||
println!("{s1}, world!");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -18,6 +18,6 @@ fn main() {
|
|||
|
||||
s.clear(); // error!
|
||||
|
||||
println!("the first word is: {}", word);
|
||||
println!("the first word is: {word}");
|
||||
}
|
||||
// ANCHOR_END: here
|
||||
|
|
|
@ -10,5 +10,5 @@ fn main() {
|
|||
height: 50,
|
||||
};
|
||||
|
||||
println!("rect1 is {:?}", rect1);
|
||||
println!("rect1 is {rect1:?}");
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ fn main() {
|
|||
height: 50,
|
||||
};
|
||||
|
||||
println!("rect1 is {:#?}", rect1);
|
||||
println!("rect1 is {rect1:#?}");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ pub mod garden;
|
|||
|
||||
fn main() {
|
||||
let plant = Asparagus {};
|
||||
println!("I'm growing {:?}!", plant);
|
||||
println!("I'm growing {plant:?}!");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@ fn main() {
|
|||
*count += 1;
|
||||
}
|
||||
|
||||
println!("{:?}", map);
|
||||
println!("{map:?}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -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:?}"),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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:?}");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ fn main() {
|
|||
r = &x;
|
||||
}
|
||||
|
||||
println!("r: {}", r);
|
||||
println!("r: {r}");
|
||||
}
|
||||
|
|
|
@ -6,5 +6,5 @@ fn main() {
|
|||
r = &x; // | |
|
||||
} // -+ |
|
||||
// |
|
||||
println!("r: {}", r); // |
|
||||
println!("r: {r}"); // |
|
||||
} // ---------+
|
||||
|
|
|
@ -3,6 +3,6 @@ fn main() {
|
|||
// |
|
||||
let r = &x; // --+-- 'a |
|
||||
// | |
|
||||
println!("r: {}", r); // | |
|
||||
println!("r: {r}"); // | |
|
||||
// --+ |
|
||||
} // ----------+
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub fn greeting(name: &str) -> String {
|
||||
format!("Hello {}!", name)
|
||||
format!("Hello {name}!")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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:?}");
|
||||
}
|
||||
|
|
|
@ -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:?}");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ fn main() {
|
|||
];
|
||||
|
||||
list.sort_by_key(|r| r.width);
|
||||
println!("{:#?}", list);
|
||||
println!("{list:#?}");
|
||||
}
|
||||
|
|
|
@ -18,5 +18,5 @@ fn main() {
|
|||
sort_operations.push(value);
|
||||
r.width
|
||||
});
|
||||
println!("{:#?}", list);
|
||||
println!("{list:#?}");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fn main() {
|
||||
let b = Box::new(5);
|
||||
println!("b = {}", b);
|
||||
println!("b = {b}");
|
||||
}
|
||||
|
|
|
@ -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:?}");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -10,5 +10,5 @@ fn main() {
|
|||
});
|
||||
|
||||
let received = rx.recv().unwrap();
|
||||
println!("Got: {}", received);
|
||||
println!("Got: {received}");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -20,6 +20,6 @@ fn main() {
|
|||
});
|
||||
|
||||
for received in rx {
|
||||
println!("Got: {}", received);
|
||||
println!("Got: {received}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ fn main() {
|
|||
});
|
||||
|
||||
for received in rx {
|
||||
println!("Got: {}", received);
|
||||
println!("Got: {received}");
|
||||
}
|
||||
|
||||
// --snip--
|
||||
|
|
|
@ -8,5 +8,5 @@ fn main() {
|
|||
*num = 6;
|
||||
}
|
||||
|
||||
println!("m = {:?}", m);
|
||||
println!("m = {m:?}");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
stack.push(3);
|
||||
|
||||
while let Some(top) = stack.pop() {
|
||||
println!("{}", top);
|
||||
println!("{top}");
|
||||
}
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fn print_coordinates(&(x, y): &(i32, i32)) {
|
||||
println!("Current location: ({}, {})", x, y);
|
||||
println!("Current location: ({x}, {y})");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fn main() {
|
||||
// ANCHOR: here
|
||||
if let x = 5 {
|
||||
println!("{}", x);
|
||||
println!("{x}");
|
||||
};
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -12,6 +12,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
println!("setting is {:?}", setting_value);
|
||||
println!("setting is {setting_value:?}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ fn main() {
|
|||
println!("found a string");
|
||||
}
|
||||
|
||||
println!("{:?}", s);
|
||||
println!("{s:?}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ fn main() {
|
|||
println!("found a string");
|
||||
}
|
||||
|
||||
println!("{:?}", s);
|
||||
println!("{s:?}");
|
||||
// ANCHOR_END: here
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ fn main() {
|
|||
|
||||
match numbers {
|
||||
(.., second, ..) => {
|
||||
println!("Some numbers: {}", second)
|
||||
println!("Some numbers: {second}")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
static HELLO_WORLD: &str = "Hello, world!";
|
||||
|
||||
fn main() {
|
||||
println!("name is: {}", HELLO_WORLD);
|
||||
println!("name is: {HELLO_WORLD}");
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@ fn main() {
|
|||
add_to_count(3);
|
||||
|
||||
unsafe {
|
||||
println!("COUNTER: {}", COUNTER);
|
||||
println!("COUNTER: {COUNTER}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue