#io-write #size-optimization #macro #replace #standard #optimized #writeln

no-std bitty_write_macro

A drop-in write! replacement that optimizes non-formatting writes for code size

3 releases

0.1.2 Mar 14, 2024
0.1.1 Mar 13, 2024
0.1.0 Mar 13, 2024

#508 in Rust patterns

Download history 197/week @ 2024-03-09 119/week @ 2024-03-16 1169/week @ 2024-03-23 2220/week @ 2024-03-30 2611/week @ 2024-04-06 1212/week @ 2024-04-13 516/week @ 2024-04-20

6,760 downloads per month

Apache-2.0

19KB
398 lines

Size-optimized versions of the standard library's write! and writeln! macros.

Why use these macros?

In code size-constrained systems that perform string formatting, using the write! or writeln! macro can generate larger code than writing the contents directly, even after linking and inlining.

The write! and writeln! macros provided by this crate detect when the write could be optimized as a direct write with write_str (for fmt::Write) or write (for io::Write) and calls that instead of format_args! and write_fmt.


lib.rs:

Size-optimized versions of the standard library's write! and writeln! macros

Why use these macros?

In code size-constrained systems that perform string formatting, using the write! or writeln! macro can generate larger code than writing the contents directly, even after linking and inlining.

The write! and writeln! macros provided by this crate detect when the write could be optimized as a direct write with write_str (for fmt::Write) or write (for io::Write) and calls that instead of format_args! and write_fmt.

The std feature

By default, this crate is #![no_std] and only supports fmt::Write. To write to io::Write sinks, enable the std feature.

Known drawbacks

These macros:

  • Target a write_str method on the trait, using an internal adapter to expose write_str on io::Write.
  • Do not currently accept concat! in the format string.
  • Do not optimize nested format_args! like write!(w, "{}", format_args!("x")).

Dependencies