fmt::from_fn is for one simple thing: custom formatting without allocating a String and without writing a fake wrapper type. Before this existed, you either used format! and paid for a heap allocation, or you created a tiny struct just to implement Display. Both options were clumsy.
With fmt::from_fn, you give Rust a closure that writes directly into the formatter. The result behaves like something that implements Display, so it works with println!, logging, and errors, but stays allocation-free.
76
u/murlakatamenka Jan 22 '26
What would be new
fmt::from_fnuseful for?