Rust: println!()
These are the usages of the println!() macro.
fn main() {
println!("{}, {}!", "Hello", "world"); // Hello, world!
println!("{0}, {1}!", "Hello", "world"); // Hello, world!
println!("{greeting}, {name}!", greeting = "Hello", name = "world"); // Hello, world!
let (greeting, name) = ("Hello", "world"); // 💡 Two Variable bindings declare & initialize in one line.
println!("{greeting}, {name}!"); // Hello, world!
println!("{:?}", [1, 2, 3]); // [1, 2, 3]
println!("{:#?}", [1, 2, 3]);
/*
[
1,
2,
3
]
*/
// 🔎 The format! macro is used to store the formatted string.
let x = format!("{}, {}!", "Hello", "world");
println!("{}", x); // Hello, world!
// 💡 Rust has a print!() macro as well
print!("Hello, world!"); // Without new line
println!(); // A new line
print!("Hello, world!\n"); // With new line
}