HNHacker News
TopNewBestAskShowJobs

parkmycar

22 karma · joined May 15, 2020

submissionscomments
parkmycar··on Small Strings in Rust: smolstr vs. smartstring (2020)
Ha, naming is hard! You’re totally right, it used to be just the values of the last byte of a UTF-8 char (and before that it was NonMaxU8) but now represents more. I’ll update it once I’m back at my computer, thanks!
parkmycar··on Small Strings in Rust: smolstr vs. smartstring (2020)
I do, mcyoung wrote a great blogpost[1] about it! Good idea, I’m AFK at the moment but will add it to the ‘Similar Crates’ section once I’m back

[1] https://mcyoung.xyz/2023/08/09/yarns/

parkmycar··on Small Strings in Rust: smolstr vs. smartstring (2020)
Author of compact_str here, you hit the nail on the head, great explanation!

> ... and another (217) signifies that it's a weird static allocation (I do not know why you'd do this)

In addition to String Rust also has str[1], which is an entirely different type. It's common to represent string literals known at compile time as `&'static str`, but they can't be used in all of the same places that a String can. For example, you can't put a &'static str into a Vec<String> unless you first heap allocate and create a String. We added the additional variant of 217 so users of CompactString could abstract over both string literals and strings created at runtime to solve cases like the example.

[1]: https://doc.rust-lang.org/std/primitive.str.html

parkmycar··on Small Strings in Rust: smolstr vs. smartstring (2020)
Hey I'm the author of compact_str, thanks for the kind words!

Fun fact, it was this fasterthanlime post that originally inspired me to play around with small strings and led to the creation of compact_str.