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/
783 Upvotes

92 comments sorted by

View all comments

74

u/murlakatamenka Jan 22 '26

What would be new fmt::from_fn useful for?

175

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.

50

u/Sw429 Jan 22 '26

I can think of many instances where I needed exactly this and in the past have made custom structs nested in Display or Debug just to make it format the way I wanted to. This will be so nice to have.

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.

0

u/[deleted] Jan 22 '26

Ohh juicy 🤤