In Rust 1.58, println!("{x}"); is supported (Captured identifiers in format strings), but I cannot print the struct because I don’t specify {:?}. Are there any ways to display struct with the new println!?
#[derive(Debug)]
struct Structure {
name: String,
version: u32
}
fn main() {
let structure = Structure { name: "name".to_string(), version: 1 };
println!("{:?}", structure); // working
println!("{structure}"); // not working
}
>Solution :
You can add the :? debug modifier as part of the formatting as well:
println!("{structure:?}");