Go seems to be able to print structs and arrays directly.
struct MyStruct { a: i32, b: i32 }
and
let arr: [i32; 10] = [1; 10];
You want to implement the Debug trait on your struct. Using #[derive(Debug)] is the easiest solution. Then you can print it with {:?}:
Debug
#[derive(Debug)]
{:?}
#[derive(Debug)] struct MyStruct{ a: i32, b: i32 } fn main() { let x = MyStruct{ a: 10, b: 20 }; println!("{:?}", x); }
1.4m articles
1.4m replys
5 comments
57.0k users