[][src]Crate lazy_format

lazy_format! is a macro which lazily formats its arguments. That is, rather than immediatly formatting them into a String (which is what format!) does, it captures its arguments and returns an opaque struct with a Display implementation, so that the actual formatting can happen directly into its final destination buffer (such as a file or string).

use std::fmt::Display;

use lazy_format::lazy_format;

// NOTE: This is obviously profoundly unsafe and you should never actually
// render HTML without escape guards, code injection prevention, etc.
fn html_tag<'a>(tag: &'a str, content: impl Display + 'a) -> impl Display + 'a {
    lazy_format!("<{tag}>{content}</{tag}>", tag=tag, content=content)
}

let result = html_tag("div", html_tag("p", "Hello, World!")).to_string();
assert_eq!(result, "<div><p>Hello, World!</p></div>");

Modules

prelude

Macros

lazy_format

Lazily format something