23 releases

0.1.23 Apr 26, 2022
0.1.21 Nov 4, 2021
0.1.18 Jun 26, 2021
0.1.17 Sep 20, 2020
0.1.7 Oct 13, 2018
Download history 19822/week @ 2022-03-09 19551/week @ 2022-03-16 19741/week @ 2022-03-23 21212/week @ 2022-03-30 23029/week @ 2022-04-06 19980/week @ 2022-04-13 19126/week @ 2022-04-20 21944/week @ 2022-04-27 23337/week @ 2022-05-04 26111/week @ 2022-05-11 22209/week @ 2022-05-18 20200/week @ 2022-05-25 24232/week @ 2022-06-01 24613/week @ 2022-06-08 23687/week @ 2022-06-15 20986/week @ 2022-06-22

97,080 downloads per month
Used in 174 crates (43 directly)

MIT/Apache

20KB
534 lines

smol_str

CI 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.

MSRV Policy

Minimal Supported Rust Version: latest stable.

Bumping MSRV is not considered a semver-breaking change.

Dependencies

~83KB