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

89 points park_my_car

Hey folks! I'm announcing version 0.7 of compact_str, a small string optimization for Rust! This library exports a single struct CompactString which can inline strings up to 24 bytes long (12 on 32-bit machines). It also exports two traits, ToCompactString and CompactStringExt, as well as a single macro format_compact!.

The most noteworthy change in this release is a refactoring to allow for use of branchless instructions when accessing the string. Whether you have an inline string or a string on the heap, accessing the content no longer requires branching, and should be just as fast as std::string::String.

Other changes in this release are:

  • Eagerly inline strings when converting From<String> and From<Box<str>>
  • New smallvec feature which enables the CompactString::into_bytes() -> SmallVec API
  • Implementation of additional traits to make CompactString more ergonomic
  • ... and more! Please see the CHANGELOG for more detail

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

​

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

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

​

Edit: replace "characters" with "bytes\