3DRX

// post

The println macro in Rust

common usage in detail

Updated

The println! macro in Rust is powerful, the following are some common use cases.

  1. Placeholder {} for any data type.
    println!("First: {}, Second: {}, Third: {}.", "a", 1, true);
    The output:
    First: a, Second: 1, Third: true.
  2. Traits for numbers
    println!("Binary: {:b} Hex: {:x} Octal: {:o}", 10, 10, 10);
    The output:
    Binary: 1010 Hex: a Octal: 12
  3. A “tuple” of values
    println!("{:?}", (10, true, "text"));
    The output:
    (10, true, "text")