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

#103 in Rust patterns

Download history 25097/week @ 2024-08-06 18153/week @ 2024-08-13 22086/week @ 2024-08-20 19715/week @ 2024-08-27 24605/week @ 2024-09-03 19113/week @ 2024-09-10 21418/week @ 2024-09-17 22293/week @ 2024-09-24 22073/week @ 2024-10-01 21829/week @ 2024-10-08 26604/week @ 2024-10-15 29718/week @ 2024-10-22 23674/week @ 2024-10-29 31336/week @ 2024-11-05 33193/week @ 2024-11-12 23308/week @ 2024-11-19

116,494 downloads per month
Used in 37 crates (17 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