#str #string #type #strings #clone

smol_str

small-string optimized string type with O(1) clone

16 releases

✓ Uses Rust 2018 edition

0.1.15 Oct 9, 2019
0.1.13 Sep 26, 2019
0.1.12 Jul 7, 2019
0.1.10 Mar 31, 2019
0.1.7 Oct 13, 2018
Download history 976/week @ 2019-06-26 875/week @ 2019-07-03 1087/week @ 2019-07-10 1337/week @ 2019-07-17 1117/week @ 2019-07-24 504/week @ 2019-07-31 479/week @ 2019-08-07 360/week @ 2019-08-14 439/week @ 2019-08-21 433/week @ 2019-08-28 406/week @ 2019-09-04 574/week @ 2019-09-11 642/week @ 2019-09-18 643/week @ 2019-09-25 663/week @ 2019-10-02

2,804 downloads per month
Used in 8 crates (4 directly)

MIT/Apache

17KB
368 lines

smol_str

Build Status Crates.io API reference

A SmolStr is a string type that has the following properties:

  • size_of::<SmolStr>() == size_of::<String>()
  • Clone is O(1)
  • Strings are stack-allocated if they are:
    • Up to 22 bytes long
    • Longer than 22 bytes, but substrings of WS (see src/lib.rs). Such strings consist solely of consecutive newlines, followed by consecutive spaces
  • If a string does not satisfy the aforementioned conditions, it is heap-allocated

Unlike String, however, SmolStr is immutable. The primary use case for SmolStr is a good enough default storage for tokens of typical programming languages. Strings consisting of a series of newlines, followed by a series of whitespace are a typical pattern in computer programs because of indentation. Note that a specialized interner might be a better solution for some use cases.

Dependencies