#fmt #fast #formatting #display

no-std fast_fmt

This crate provides faster, more flexible and more correct alternative to core::fmt

2 releases

Uses old Rust 2015

0.1.3 Jul 2, 2017
0.1.2 Jun 3, 2017
0.1.1 May 30, 2017
0.1.0 May 29, 2017

#2318 in Rust patterns

Download history 27/week @ 2023-08-12 16/week @ 2023-08-19 17/week @ 2023-08-26 25/week @ 2023-09-02 21/week @ 2023-09-09 16/week @ 2023-09-16 8/week @ 2023-09-23 19/week @ 2023-09-30 18/week @ 2023-10-07 21/week @ 2023-10-14 21/week @ 2023-10-21 27/week @ 2023-10-28 23/week @ 2023-11-04 24/week @ 2023-11-11 23/week @ 2023-11-18 36/week @ 2023-11-25

106 downloads per month
Used in 4 crates

MITNFA license

460 lines

Fast fmt

Faster, more flexible and more correct alternative to core::fmt (AKA std::fmt)


This is WIP. Some APIs may change, some may lack documentation, others may be broken. Information in this README (especially benchmarks) may be misleading. Contributions are highly appreciated!

I don't promise to work on this much for a while!

Why is this faster?

  • Lack of trait objects allows compiler to optimize better.
  • Use of size_hint allows writers to e.g. pre-allocate large enough buffer.
  • Use of never type for errors comming from Write allows to optimize-out error checks.

Why more flexible?

Instead of multiple traits like Display, Debug, ... this crate defines single Fmt<S> which allows you to implement multiple different strategies, even your own. One possible use case is to implement Fmt<Localizer> to enable localization of your application.

Why more correct?

Instead of returning Err(()) on failed writes it returns apropriate types. It can even be Void to represent writers that can never fail (e.g. std::string::String).

How fast is it in practice?

The crate provides a very simple benchmark:

test bench::bench_core_fmt ... bench:         122 ns/iter (+/- 24)
test bench::bench_fast_fmt ... bench:          26 ns/iter (+/- 1)

It's consistently more than four times faster!

What to improve?

Roughly sorted by priority.

  • Documentation
  • Macros - ideally provide the same experience as core does.
  • More strategies
  • More impls (especially Fmt for primitives)
  • Bridge with core::fmt
  • Bridge with T: Iterator<char> + Clone?
  • Integrate with genio and provide encoders for different encodings.
  • Support for trait objects if someone want's them
  • Transformers (e.g. char escaping)
  • Asynchronous formatting maybe?
  • PR aginst core
  • Deprecate core::fmt

Last two are jokes.