mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-08 10:36:17 +02:00
Inline variables printed with println!
and friends (#315)
The course follows the style of inlining variable names where possible in `println!` statements.
This commit is contained in:
parent
ce19841249
commit
c4bc10e31d
@ -21,7 +21,7 @@ fn main() {
|
|||||||
thread::sleep(Duration::from_millis(100));
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
|
||||||
for msg in rx.iter() {
|
for msg in rx.iter() {
|
||||||
println!("Main: got {}", msg);
|
println!("Main: got {msg}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -24,7 +24,7 @@ pub trait Widget {
|
|||||||
fn draw(&self) {
|
fn draw(&self) {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
self.draw_into(&mut buffer);
|
self.draw_into(&mut buffer);
|
||||||
println!("{}", &buffer);
|
println!("{buffer}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,6 @@ fn main() {
|
|||||||
|
|
||||||
drop(tx);
|
drop(tx);
|
||||||
for thought in rx {
|
for thought in rx {
|
||||||
println!("{}", thought);
|
println!("{thought}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ We've seen how a function can take arguments which implement a trait:
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
fn print<T: Display>(x: T) {
|
fn print<T: Display>(x: T) {
|
||||||
println!("Your value: {}", x);
|
println!("Your value: {x}");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -6,7 +6,7 @@ It is safe to read an immutable static variable:
|
|||||||
static HELLO_WORLD: &str = "Hello, world!";
|
static HELLO_WORLD: &str = "Hello, world!";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("HELLO_WORLD: {}", HELLO_WORLD);
|
println!("HELLO_WORLD: {HELLO_WORLD}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ fn add_to_counter(inc: u32) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
add_to_counter(42);
|
add_to_counter(42);
|
||||||
|
|
||||||
unsafe { println!("COUNTER: {}", COUNTER); } // Potential data race!
|
unsafe { println!("COUNTER: {COUNTER}"); } // Potential data race!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user