22 stable releases

2.0.3 Nov 29, 2023
2.0.0 Aug 11, 2022
1.10.0 Dec 5, 2021
1.9.0 Aug 21, 2021
1.2.1 Feb 16, 2019

#96 in Rust patterns

Download history 24962/week @ 2024-11-30 24769/week @ 2024-12-07 24868/week @ 2024-12-14 5120/week @ 2024-12-21 7751/week @ 2024-12-28 23760/week @ 2025-01-04 34815/week @ 2025-01-11 26377/week @ 2025-01-18 31600/week @ 2025-01-25 35748/week @ 2025-02-01 38477/week @ 2025-02-08 29045/week @ 2025-02-15 32934/week @ 2025-02-22 29328/week @ 2025-03-01 31803/week @ 2025-03-08 28672/week @ 2025-03-15

128,561 downloads per month
Used in 39 crates (19 directly)

MPL-2.0 license

20KB
150 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