From c4bc10e31d91754fb3751ca04da7b0553cd48779 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Thu, 9 Feb 2023 07:48:18 +0100 Subject: [PATCH] Inline variables printed with `println!` and friends (#315) The course follows the style of inlining variable names where possible in `println!` statements. --- src/concurrency/channels/bounded.md | 2 +- src/exercises/day-3/simple-gui.rs | 2 +- src/exercises/day-4/dining-philosophers.rs | 2 +- src/generics/trait-objects.md | 2 +- src/unsafe/mutable-static-variables.md | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/concurrency/channels/bounded.md b/src/concurrency/channels/bounded.md index 1bbc38c3..ba453c2a 100644 --- a/src/concurrency/channels/bounded.md +++ b/src/concurrency/channels/bounded.md @@ -21,7 +21,7 @@ fn main() { thread::sleep(Duration::from_millis(100)); for msg in rx.iter() { - println!("Main: got {}", msg); + println!("Main: got {msg}"); } } ``` diff --git a/src/exercises/day-3/simple-gui.rs b/src/exercises/day-3/simple-gui.rs index 60ae67ff..3bcd72c3 100644 --- a/src/exercises/day-3/simple-gui.rs +++ b/src/exercises/day-3/simple-gui.rs @@ -24,7 +24,7 @@ pub trait Widget { fn draw(&self) { let mut buffer = String::new(); self.draw_into(&mut buffer); - println!("{}", &buffer); + println!("{buffer}"); } } diff --git a/src/exercises/day-4/dining-philosophers.rs b/src/exercises/day-4/dining-philosophers.rs index fc33d3dc..28807b62 100644 --- a/src/exercises/day-4/dining-philosophers.rs +++ b/src/exercises/day-4/dining-philosophers.rs @@ -90,6 +90,6 @@ fn main() { drop(tx); for thought in rx { - println!("{}", thought); + println!("{thought}"); } } diff --git a/src/generics/trait-objects.md b/src/generics/trait-objects.md index a5489f55..7c80f0b8 100644 --- a/src/generics/trait-objects.md +++ b/src/generics/trait-objects.md @@ -6,7 +6,7 @@ We've seen how a function can take arguments which implement a trait: use std::fmt::Display; fn print(x: T) { - println!("Your value: {}", x); + println!("Your value: {x}"); } fn main() { diff --git a/src/unsafe/mutable-static-variables.md b/src/unsafe/mutable-static-variables.md index 80f60d15..75cf49e3 100644 --- a/src/unsafe/mutable-static-variables.md +++ b/src/unsafe/mutable-static-variables.md @@ -6,7 +6,7 @@ It is safe to read an immutable static variable: static HELLO_WORLD: &str = "Hello, world!"; fn main() { - println!("HELLO_WORLD: {}", HELLO_WORLD); + println!("HELLO_WORLD: {HELLO_WORLD}"); } ``` @@ -23,7 +23,7 @@ fn add_to_counter(inc: u32) { fn main() { add_to_counter(42); - unsafe { println!("COUNTER: {}", COUNTER); } // Potential data race! + unsafe { println!("COUNTER: {COUNTER}"); } // Potential data race! } ```