rust - How to print structs and arrays? -


go seems able print structs , arrays directly.

struct mystruct {     a: i32,     b: i32 } 

and

let arr: [i32; 10] = [1; 10]; 

you want implement debug trait on struct. using #[derive(debug)] easiest solution. can print {:?}:

#[derive(debug)] struct mystruct{     a: i32,     b: i32 }  fn main() {     let x = mystruct{ a: 10, b: 20 };     println!("{:?}", x); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -