7 releases

0.2.5 Sep 24, 2020
0.2.4 Sep 5, 2020
0.2.3 Jul 7, 2020
0.1.0 May 15, 2020

#156 in Data structures

Download history 214/week @ 2020-08-07 314/week @ 2020-08-14 1748/week @ 2020-08-21 597/week @ 2020-08-28 886/week @ 2020-09-04 943/week @ 2020-09-11 819/week @ 2020-09-18 624/week @ 2020-09-25 302/week @ 2020-10-02 737/week @ 2020-10-09 665/week @ 2020-10-16 4183/week @ 2020-10-23 5911/week @ 2020-10-30 5960/week @ 2020-11-06 5681/week @ 2020-11-13 5302/week @ 2020-11-20

2,267 downloads per month
Used in 35 crates (14 directly)

MPL-2.0+

82KB
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, and when not inlined it's pointer compatible with String, meaning that you can safely coerce a SmartString to a String using std::mem::replace() or pointer::cast() and go on using it as if it had never been a SmartString. (But please don't do that, there's an Into<String> implementation that's much safer.)

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

~43–600KB
~11K SLoC