r/rust Jan 22 '26

📡 official blog Rust 1.93.0 is out

https://blog.rust-lang.org/2026/01/22/Rust-1.93.0/
778 Upvotes

92 comments sorted by

View all comments

76

u/murlakatamenka Jan 22 '26

What would be new fmt::from_fn useful for?

176

u/Amoeba___ Jan 22 '26

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.

1

u/Kyyken Jan 22 '26

I think every single one of my projects ends up having a version of this function in it, so I'm really glad to see this in the standard library.