From 0f2f88b3880d7c59c97af1c2bd305e681c9dd361 Mon Sep 17 00:00:00 2001 From: Eric Githinji Date: Tue, 25 Feb 2025 16:24:18 +0000 Subject: [PATCH] Use dbg! instead of println! in Day 2. Part of #2478 to clean up code blocks when all that is needed is a trivial debug print statement. As mentioned in previous related PRs, in some places I've opted to retain the use of println! because dbg! makes it less readable. --- src/generics/generic-traits.md | 3 ++- src/generics/impl-trait.md | 6 +++--- src/pattern-matching/let-control-flow/while-let.md | 4 +--- src/std-traits/default.md | 6 +++--- src/std-types/hashmap.md | 2 +- src/std-types/option.md | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/generics/generic-traits.md b/src/generics/generic-traits.md index c7121dae3372..40174f1d1eef 100644 --- a/src/generics/generic-traits.md +++ b/src/generics/generic-traits.md @@ -33,7 +33,8 @@ impl From for Foo { fn main() { let from_int = Foo::from(123); let from_bool = Foo::from(true); - println!("{from_int:?}, {from_bool:?}"); + dbg!(from_int); + dbg!(from_bool); } ``` diff --git a/src/generics/impl-trait.md b/src/generics/impl-trait.md index 8639f9ebfe8a..44323955da15 100644 --- a/src/generics/impl-trait.md +++ b/src/generics/impl-trait.md @@ -20,11 +20,11 @@ fn pair_of(x: u32) -> impl std::fmt::Debug { fn main() { let many = add_42_millions(42_i8); - println!("{many}"); + dbg!(many); let many_more = add_42_millions(10_000_000); - println!("{many_more}"); + dbg!(many_more); let debuggable = pair_of(27); - println!("debuggable: {debuggable:?}"); + dbg!(debuggable); } ``` diff --git a/src/pattern-matching/let-control-flow/while-let.md b/src/pattern-matching/let-control-flow/while-let.md index 19628fd3b211..ca58bb6e7431 100644 --- a/src/pattern-matching/let-control-flow/while-let.md +++ b/src/pattern-matching/let-control-flow/while-let.md @@ -4,13 +4,11 @@ Like with `if let`, there is a [`while let`](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops) variant which repeatedly tests a value against a pattern: - - ```rust,editable fn main() { let mut name = String::from("Comprehensive Rust 🩀"); while let Some(c) = name.pop() { - println!("character: {c}"); + dbg!(c); } // (There are more efficient ways to reverse a string!) } diff --git a/src/std-traits/default.md b/src/std-traits/default.md index 333510acfce8..dee1bb5531b6 100644 --- a/src/std-traits/default.md +++ b/src/std-traits/default.md @@ -25,14 +25,14 @@ impl Default for Implemented { fn main() { let default_struct = Derived::default(); - println!("{default_struct:#?}"); + dbg!(default_struct); let almost_default_struct = Derived { y: "Y is set!".into(), ..Derived::default() }; - println!("{almost_default_struct:#?}"); + dbg!(almost_default_struct); let nothing: Option = None; - println!("{:#?}", nothing.unwrap_or_default()); + dbg!(nothing.unwrap_or_default()); } ``` diff --git a/src/std-types/hashmap.md b/src/std-types/hashmap.md index e611902cff20..88ce026c15f5 100644 --- a/src/std-types/hashmap.md +++ b/src/std-types/hashmap.md @@ -35,7 +35,7 @@ fn main() { *page_count += 1; } - println!("{page_counts:#?}"); + dbg!(page_counts); } ``` diff --git a/src/std-types/option.md b/src/std-types/option.md index 903210790489..1b2190b42fdc 100644 --- a/src/std-types/option.md +++ b/src/std-types/option.md @@ -13,10 +13,10 @@ returns an `Option`. fn main() { let name = "Löwe 老虎 LĂ©opard Gepardi"; let mut position: Option = name.find('Ă©'); - println!("find returned {position:?}"); + dbg!(position); assert_eq!(position.unwrap(), 14); position = name.find('Z'); - println!("find returned {position:?}"); + dbg!(position); assert_eq!(position.expect("Character not found"), 0); } ```