Skip to content

Commit

Permalink
Use dbg! instead of println! in Day 2. (#2657)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Eric Githinji <[email protected]>
  • Loading branch information
egithinji and Eric Githinji authored Feb 25, 2025
1 parent 32a8b4b commit 1a64c9b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/generics/generic-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ impl From<bool> 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);
}
```

Expand Down
6 changes: 3 additions & 3 deletions src/generics/impl-trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```

Expand Down
4 changes: 1 addition & 3 deletions src/pattern-matching/let-control-flow/while-let.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<!-- mdbook-xgettext: skip -->

```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!)
}
Expand Down
6 changes: 3 additions & 3 deletions src/std-traits/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Derived> = None;
println!("{:#?}", nothing.unwrap_or_default());
dbg!(nothing.unwrap_or_default());
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/std-types/hashmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
*page_count += 1;
}
println!("{page_counts:#?}");
dbg!(page_counts);
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/std-types/option.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ returns an `Option<usize>`.
fn main() {
let name = "Löwe 老虎 Léopard Gepardi";
let mut position: Option<usize> = 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);
}
```
Expand Down

0 comments on commit 1a64c9b

Please sign in to comment.