mirror of
https://bitbucket.org/Mattrixwv/rusttutorials.git
synced 2025-12-07 11:03:58 -05:00
Updated naming again
This commit is contained in:
38
1.HelloWorld/2.FormattedPrint/1Debugging.rs
Normal file
38
1.HelloWorld/2.FormattedPrint/1Debugging.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
fn main(){
|
||||
//Printing with `{:?}` is similar to with `{}`.
|
||||
println!("{:?} months in a year.", 12);
|
||||
println!("{1:?} {0:?} is the {actor:?} name.",
|
||||
"Slater",
|
||||
"Christian",
|
||||
actor="actor's");
|
||||
|
||||
//`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 = "Peter";
|
||||
let age = 27;
|
||||
let peter = Person { name, age };
|
||||
|
||||
//Pretty print
|
||||
println!("{:#?}", peter);
|
||||
}
|
||||
Reference in New Issue
Block a user