You want to implement the Debug
trait on your struct. Using #[derive(Debug)]
is the easiest solution. Then you can print it with {:?}
:
#[derive(Debug)]
struct MyStruct{
a: i32,
b: i32
}
fn main() {
let x = MyStruct{ a: 10, b: 20 };
println!("{:?}", x);
}
More Related Contents:
- Return local String as a slice (&str)
- How to get a reference to a concrete type from a trait object?
- How do I return a reference to something inside a RefCell without breaking encapsulation?
- Conditionally iterate over one of several possible iterators
- Is there any way to create a type alias for multiple traits?
- How to convert a String into a &’static str
- What’s an idiomatic way to print an iterator separated by spaces in Rust?
- What are move semantics in Rust?
- println! error: expected a literal / format argument must be a string literal
- How do I return an instance of a trait from a method?
- “borrowed value does not live long enough” seems to blame the wrong thing
- Weird behaviour when using read_line in a loop
- How can this instance seemingly outlive its own parameter lifetime?
- Why are Rust executables so huge?
- What do I have to do to solve a “use of moved value” error?
- Why does removing return give me an error: expected type `()` but found type
- How do I implement a trait with a generic method?
- Linking the lifetimes of self and a reference in method
- When I can use either Cell or RefCell, which should I choose?
- Can I take a byte array and deserialize it into a struct?
- How do I create a Rust callback function to pass to a FFI function?
- What is an auto trait in Rust?
- Borrow pointer errors recursively traversing tree [duplicate]
- How can I borrow from a HashMap to read and write at the same time?
- How to print a Vec?
- How to get an Option’s value or set it if it’s empty?
- How to set a field in a struct with an empty value?
- How can I solve “use of moved value” and “which does not implement the `Copy` trait”?
- Why does using Option::map to Box::new a trait object not work?
- Is the resource of a shadowed variable binding freed immediately?