18 releases

0.1.17 Sep 20, 2020
0.1.16 Jul 6, 2020
0.1.15 Oct 9, 2019
0.1.12 Jul 7, 2019
0.1.7 Oct 13, 2018
Download history 9312/week @ 2020-07-02 9674/week @ 2020-07-09 6613/week @ 2020-07-16 7714/week @ 2020-07-23 8953/week @ 2020-07-30 8948/week @ 2020-08-06 9870/week @ 2020-08-13 9235/week @ 2020-08-20 9867/week @ 2020-08-27 9608/week @ 2020-09-03 9290/week @ 2020-09-10 9787/week @ 2020-09-17 11538/week @ 2020-09-24 12280/week @ 2020-10-01 11670/week @ 2020-10-08 10380/week @ 2020-10-15

38,247 downloads per month
Used in 61 crates (15 directly)

MIT/Apache

19KB
507 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

~70KB