Printing structs and values in Rust (like Go's fmt.Println).
| Macro | Trait Required | Use Case |
|---|---|---|
println!("{}", x) |
Display |
Human-readable output |
println!("{:?}", x) |
Debug |
Developer/debug output |
println!("{:#?}", x) |
Debug |
Pretty-printed debug |
Debug for Your Structs#[derive(Debug, Deserialize)]
pub struct ExchangeInfo {
pub symbols: Vec<Symbol>,
}
#[derive(Debug, Deserialize)]
pub struct Symbol {
pub symbol: String,
}
Then use:
let info = client.fetch_exchange_info().await?;
println!("{:#?}", info); // Pretty prints the whole struct
| Go | Rust |
|---|---|
fmt.Println(x) |
println!("{:?}", x) |
fmt.Printf("%+v", x) |
println!("{:#?}", x) |
Rust doesn't auto-cast for printing—you need Debug or Display traits.