Announcing `compact_str` version 0.5! A small string optimization for Rust

130 points park_my_car

Hey folks, I'm announcing version 0.5 of compact_str, a small string optimization for Rust! This library exports a struct CompactString which can inline strings up to 24 characters long (12 on 32-bit machines), and two traits, ToCompactString and CompactStringExt, which expose methods for turning different types into a CompactString. As well as a single macro, format_compact!, which allows you to create a CompactString from various arguments.

With this release comes several improvements:

  • Option<CompactString> is the same size as CompactString, wrapping in an Option<_> no longer requires additional padding
  • A new macro,format_compact! which allows you to create a CompactString just like you would create a String with the std::format! macro
  • A new trait, CompactStringExt, which exports two methods join_compact(seperator) and concat_compact(), which allow you to construct a CompactString from a collection of items
  • Implements AsRef<OsStr> for CompactString
  • Various performance improvements

GitHub: https://github.com/ParkMyCar/compact\_str

crates.io: https://crates.io/crates/compact\_str

​

Special thanks to u/Nilstrieb, u/NobodyXu, and u/CAD97 for their contributions! 🎉