#lazy #format #health #formatting #lazy-evaluation #macro #utility

no-std lazy_format

A utility crate for lazily formatting values for later

19 stable releases

2.0.0 Aug 11, 2022
1.10.0 Dec 5, 2021
1.9.0 Aug 21, 2021
1.8.4 Apr 22, 2021
1.2.1 Feb 16, 2019

#76 in Rust patterns

Download history 10618/week @ 2022-11-26 9031/week @ 2022-12-03 10218/week @ 2022-12-10 4758/week @ 2022-12-17 2155/week @ 2022-12-24 6622/week @ 2022-12-31 8403/week @ 2023-01-07 10738/week @ 2023-01-14 11308/week @ 2023-01-21 9686/week @ 2023-01-28 7969/week @ 2023-02-04 11360/week @ 2023-02-11 13341/week @ 2023-02-18 11821/week @ 2023-02-25 12795/week @ 2023-03-04 8046/week @ 2023-03-11

48,758 downloads per month
Used in 17 crates (4 directly)

MPL-2.0 license

17KB
98 lines

Travis (.com) Crates.io docs.rs license

lazy_format

A [no_std] library for lazily formatting things. Because allocating temporary strings just to write them to a buffered stream is bad for your health.

use std::io;

use lazy_format::lazy_format;
use joinery::JoinableIterator;

fn main() {
	let result = (0..10)
		.map(|value| lazy_format!("\t'{}'", value))
		.join_with(",\n")
		.to_string();

	assert_eq!(result,
"	'0'
	'1'
	'2'
	'3'
	'4'
	'5'
	'6'
	'7'
	'8'
	'9'")
}

The above example is the key motivating example: when building up some kind of object you wish to write or format, there's no reason to allocate intermediary strings (which is what format! does). Instead, lazy_format! 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).

No runtime deps