Macro interpolator::list

source ·
macro_rules! list {
    ($($(: $($trait:tt)?)*;)?($values:expr), *) => { ... };
}
Expand description

Creates a list of formattable values, applying th specified traits, or display if without a trait specifier.

use interpolator::{iformat, list};
// a list implementing Display
let list = list![: ;"test", 10, "another"];
let list = list![;"test", 10, "another"];
let list = list!["test", 10, "another"];
assert_eq!(
    iformat!("{list:i({})(, )}", list:i).unwrap(),
    "test, 10, another"
);
// a list implementing Display, Debug and UpperHex
let list = list![: :?:X; 4, 0x10, 0xa4];
assert_eq!(
    iformat!("{list:i({} {:?} {:X})(, )}", list:i).unwrap(),
    "4 4 4, 16 16 10, 164 164 A4"
);

Due to borrow rules you might need to create let bindings for the items, i.e.

let test = String::from("test");
let list = list![test];

instead of

let list = list![String::from("test")];