The println macro in Rust
common usage in detail
Last updated on
The println!
macro in Rust is powerful, the following are some common use cases.
- Placeholder
{}
for any data type.
The output:println!("First: {}, Second: {}, Third: {}.", "a", 1, true);
First: a, Second: 1, Third: true.
- Traits
for numbers
The output:println!("Binary: {:b} Hex: {:x} Octal: {:o}", 10, 10, 10);
Binary: 1010 Hex: a Octal: 12
- A βtupleβ of values
The output:println!("{:?}", (10, true, "text"));
(10, true, "text")