Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielAdeniji/d53140ff0f5b3eadd1cb4db12b9c14a0 to your computer and use it in GitHub Desktop.
Save DanielAdeniji/d53140ff0f5b3eadd1cb4db12b9c14a0 to your computer and use it in GitHub Desktop.
/*
Specify that structure implements the Debug trait
i.e. we will be able to print structure contents by using {:?} specifier in our print statements
*/
#[derive(Debug)]
struct Person
{
name: String
, age: u8
}
fn main()
{
// Create struct with field init shorthand
//String Literals ( static )
let nameHardCoded = "Peter 1";
let age1 = 27;
let objPeter1 = Person
{
name:nameHardCoded.to_string()
, age:age1
};
//Debug Basic Print Person 1
println!
(
"{0:?}"
, objPeter1
);
println!("");
println!("");
//Debug Pretty Print Person 1
println!
(
"{0:#?}"
, objPeter1
);
println!("");
println!("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment