mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-15 23:26:48 +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 z = 13;
|
||||||
let x = {
|
let x = {
|
||||||
let y = 10;
|
let y = 10;
|
||||||
println!("y: {y}");
|
dbg!(y);
|
||||||
z - y
|
z - y
|
||||||
};
|
};
|
||||||
println!("x: {x}");
|
dbg!(x);
|
||||||
// println!("y: {y}");
|
// dbg!(y);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -27,6 +27,9 @@ A variable's scope is limited to the enclosing block.
|
|||||||
|
|
||||||
<details>
|
<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
|
- 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`.
|
the block. For instance, adding/removing a semicolon or using a `return`.
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ fn main() {
|
|||||||
if i % 2 == 0 {
|
if i % 2 == 0 {
|
||||||
continue;
|
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() {
|
fn main() {
|
||||||
println!("gcd: {}", gcd(143, 52));
|
dbg!(gcd(143, 52));
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -19,6 +19,6 @@ fn main() {
|
|||||||
while x >= 10 {
|
while x >= 10 {
|
||||||
x = x / 2;
|
x = x / 2;
|
||||||
}
|
}
|
||||||
println!("Final x: {x}");
|
dbg!(x);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -6,11 +6,11 @@ ranges of values or the items in a collection:
|
|||||||
```rust,editable
|
```rust,editable
|
||||||
fn main() {
|
fn main() {
|
||||||
for x in 1..5 {
|
for x in 1..5 {
|
||||||
println!("x: {x}");
|
dbg!(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
for elem in [2, 4, 8, 16, 32] {
|
for elem in [2, 4, 8, 16, 32] {
|
||||||
println!("elem: {elem}");
|
dbg!(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -8,7 +8,7 @@ fn main() {
|
|||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
loop {
|
loop {
|
||||||
i += 1;
|
i += 1;
|
||||||
println!("{i}");
|
dbg!(i);
|
||||||
if i > 100 {
|
if i > 100 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user