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
Post a Comment