mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-15 15:16:51 +02:00
Use dbg! instead of println! in Day 1 mng session (#2652)
As mentioned in #2478, this cleans up the code blocks when all that is needed is a trivial debug print statement. Only making changes to Day 1 morning session so that I can get feedback before proceeding with the rest of the course. --------- Co-authored-by: Eric Githinji <egithinji@google.com>
This commit is contained in:
parent
49e4efcd9e
commit
0daab179e9
@ -13,11 +13,11 @@ fn main() {
|
||||
let z = 13;
|
||||
let x = {
|
||||
let y = 10;
|
||||
println!("y: {y}");
|
||||
dbg!(y);
|
||||
z - y
|
||||
};
|
||||
println!("x: {x}");
|
||||
// println!("y: {y}");
|
||||
dbg!(x);
|
||||
// dbg!(y);
|
||||
}
|
||||
```
|
||||
|
||||
@ -27,6 +27,9 @@ A variable's scope is limited to the enclosing block.
|
||||
|
||||
<details>
|
||||
|
||||
- You can explain that dbg! is a Rust macro that prints and returns the value of
|
||||
a given expression for quick and dirty debugging.
|
||||
|
||||
- You can show how the value of the block changes by changing the last line in
|
||||
the block. For instance, adding/removing a semicolon or using a `return`.
|
||||
|
||||
|
@ -23,7 +23,7 @@ fn main() {
|
||||
if i % 2 == 0 {
|
||||
continue;
|
||||
}
|
||||
println!("{}", i);
|
||||
dbg!(i);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -16,7 +16,7 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
print!("elements searched: {elements_searched}");
|
||||
dbg!(elements_searched);
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -16,7 +16,7 @@ fn gcd(a: u32, b: u32) -> u32 {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("gcd: {}", gcd(143, 52));
|
||||
dbg!(gcd(143, 52));
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -19,6 +19,6 @@ fn main() {
|
||||
while x >= 10 {
|
||||
x = x / 2;
|
||||
}
|
||||
println!("Final x: {x}");
|
||||
dbg!(x);
|
||||
}
|
||||
```
|
||||
|
@ -6,11 +6,11 @@ ranges of values or the items in a collection:
|
||||
```rust,editable
|
||||
fn main() {
|
||||
for x in 1..5 {
|
||||
println!("x: {x}");
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
for elem in [2, 4, 8, 16, 32] {
|
||||
println!("elem: {elem}");
|
||||
dbg!(elem);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -8,7 +8,7 @@ fn main() {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
i += 1;
|
||||
println!("{i}");
|
||||
dbg!(i);
|
||||
if i > 100 {
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user