[][src]Macro const_format::formatc

macro_rules! formatc {
    ($format_string:expr $( $(, $expr:expr )+ )? $(,)? ) => { ... };
    (@inner (($path:path)) $($everything:tt)*  ) => { ... };
}

Formats constants of standard library and/or user-defined types into a &'static str.

Syntax

This macro uses the syntax described in the const_format::fmt module

Limitations

This macro has the limitations described in here.

Example

#![feature(const_mut_refs)]

use const_format::for_examples::Point3;
use const_format::formatc;

// Formatting a non-std struct.
const POINT: &str = formatc!("{:?}", Point3{x: 8, y: 13, z: 21});

// Formatting a number as decimal, hexadecimal, and binary
const NUMBER: &str = formatc!("{0},{0:x},{0:b}", 10u8);

// Formatting the numbers in an array as decimal, hexadecimal, and binary.
// You can use the name of cnstants from scope, as well as named arguments.
const ARR: &[u32] = &[9, 25];
const ARRAY: &str = formatc!("{ARR:?},{ARR:x},{ARR:b}");


assert_eq!(POINT, "Point3 { x: 8, y: 13, z: 21 }");
assert_eq!(NUMBER, "10,A,1010");
assert_eq!(ARRAY, "[9, 25],[9, 19],[1001, 11001]");