[go: up one dir, main page]

compact_str 0.1.0

A memory efficient immutable string type that transparently stores strings on the stack, when possible
Documentation

CompactStr is a compact immutable string type that stores itself on the stack, if possible, and seamlessly interacts with Strings and &strs.

Memory Layout

Normally strings are stored on the heap, since they're dynamically sized. In Rust a String consists of three things:

  1. A usize denoting the length of the string
  2. A pointer to a location on the heap where the string is stored
  3. A usize denoting the capacity of the string

On 64-bit architectures this results in 24 bytes being stored on the stack, 12 bytes for 32-bit architectures. For small strings, e.g. < 23 characters