File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,28 @@ rect1 is Rectangle {
252
252
}
253
253
```
254
254
255
+ Now that we're familiar with deriving the ` Debug ` trait for helpful ` println! `
256
+ formatting, let's take a look at a macro that builds on top of that functionality.
257
+ The ` dbg! ` macro (available in Rust 1.32.0 and later) can accept any argument
258
+ that implements the ` Debug ` trait, and will print helpful debugging context in
259
+ the same style as ` println!("{:?#}", rect1) ` , plus the filename and line number.
260
+
261
+ <span class =" filename " >Filename: src/main.rs</span >
262
+
263
+ ``` rust
264
+ #[derive(Debug )]
265
+ struct Rectangle {
266
+ width : u32 ,
267
+ height : u32 ,
268
+ }
269
+
270
+ fn main () {
271
+ let rect1 = Rectangle { width : 30 , height : 50 };
272
+
273
+ dbg! (rect1 );
274
+ }
275
+ ```
276
+
255
277
Rust has provided a number of traits for us to use with the ` derive ` annotation
256
278
that can add useful behavior to our custom types. Those traits and their
257
279
behaviors are listed in Appendix C. We’ll cover how to implement these traits
You can’t perform that action at this time.
0 commit comments