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

55 points park_my_car

Hey folks, I'm announcing version 0.4 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 a trait ToCompactString which exposes a method for turning types into a CompactString.

With this release comes several improvements:

  • Rename CompactStr to CompactString to better reflect that we own the underlying string buffer
  • Introduce the ToCompactString trait with specializations for some basic types
  • Implement various Add<T> for CompactString, allowing concatenation with +
  • Several performance improvements around the creation of a CompactString
  • Implements std::fmt::Write for CompactString
  • O(1) conversion from String and Box<str>
  • Implements Extend<Cow<'_, str>> and From<Cow<'_, str>> for CompactString

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

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

​

Special thanks to u/kijewski_, @mcronce, u/NobodyXu, and u/CAD1997 for their contributions!