-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.rs
More file actions
29 lines (24 loc) · 777 Bytes
/
debug.rs
File metadata and controls
29 lines (24 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Derive the `fmt::Debug` implementation for `Structure`. `Structure`
// is a structure which contains a single `i32`.
#[derive(Debug)]
struct Structure(i32);
// Put a `Structure` inside of the structure `Deep`. Make it printable also.
#[derive(Debug)]
struct Deep(Structure);
#[derive(Debug)]
struct Person<'a> {
name: &'a str,
age: u8
}
pub fn play() {
// `Structure` is printable!
println!("Now {:?} will print!", Structure(3));
// The problem with `derive` is there is no control over how
// the results look. What if I want this to just show a `7`?
println!("Now {:?} will print!", Deep(Structure(7)));
let name = "muhammed";
let age = 27;
let muhammed = Person{name, age};
// Pretty print
println!("{:#?}", muhammed);
}