[][src]Macro fomat_macros::lazy_fomat

macro_rules! lazy_fomat {
    (move $($arg:tt)*) => { ... };
    ($($arg:tt)*) => { ... };
}

Creates a displayable object based on its arguments.

This macro works in a similar way to fomat, but instead of String it returns an object (DisplayFn) that implements Display and can be printed later (using format, fomat or calling Display::fmt directly).

See the crate root for general help on the syntax.

Prefix the arguments with move to force moving all variables (can help when 'static bound is required).

Examples

Direct usage

let fence = lazy_fomat!(for _ in 0..5 { "-" });
let s = fomat!((fence)" hello "(fence));

assert_eq!(s, "----- hello -----");

Returning impl Display

fn greet(name: String) -> impl ::std::fmt::Display {
    lazy_fomat!(move "Hello, "(name)"!")
}

assert_eq!(greet("World".into()).to_string(), "Hello, World!");