14 releases (2 stable)

1.0.1 Mar 24, 2022
1.0.0 Feb 24, 2022
0.2.10 Feb 20, 2022
0.2.9 Jul 27, 2021
0.1.0 May 15, 2020

#41 in Data structures

Download history 165494/week @ 2024-07-23 170126/week @ 2024-07-30 168255/week @ 2024-08-06 174799/week @ 2024-08-13 202437/week @ 2024-08-20 185859/week @ 2024-08-27 188534/week @ 2024-09-03 168729/week @ 2024-09-10 143848/week @ 2024-09-17 171609/week @ 2024-09-24 173000/week @ 2024-10-01 165417/week @ 2024-10-08 181278/week @ 2024-10-15 180819/week @ 2024-10-22 176489/week @ 2024-10-29 157192/week @ 2024-11-05

723,589 downloads per month
Used in 988 crates (105 directly)

MPL-2.0+

88KB
2K SLoC

smartstring

Compact inlined strings.

tl;dr

String type that's source compatible with std::string::String, uses exactly the same amount of space, doesn't heap allocate for short strings (up to 23 bytes on 64-bit archs) by storing them in the space a String would have taken up on the stack, making strings go faster overall.

Overview

This crate provides a wrapper for Rust's standard String which uses the space a String occupies on the stack to store inline string data, automatically promoting it to a String when it grows beyond the inline capacity. This has the advantage of avoiding heap allocations for short strings as well as improving performance thanks to keeping the strings on the stack.

This is all accomplished without the need for an external discriminant, so a SmartString is exactly the same size as a String on the stack, regardless of whether it's inlined or not. Converting a heap allocated SmartString into a String and vice versa is also a zero cost operation, as one will reuse the allocated memory of the other.

Documentation

Licence

Copyright 2020 Bodil Stokke

This software is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Dependencies

~38–770KB
~14K SLoC