Hacker News new | past | comments | ask | show | jobs | submit login

Another rust type you should look out for is Box<str>In my rust code I find a lot more uses of Box<str> rather than Box<[T]>. Strings are often fixed length identifiers or usernames that get passed around frequently and stored in data structures. Box<str> can be a drop-in replacement in a surprising amount of code



Arc<str> is an atomically ref-counted string, also quite useful in async or multi-threaded code where (unlike w/ Box) you sometimes can't know in advance which task will drop the last reference to some data.


Box<str> is used pervasively in the rust compiler instead of String for exactly this reason. Basically every string of code the compiler looks at is, unsurprisingly, constant.


Yeah, the general concept here is https://en.wikipedia.org/wiki/String_interning, Box<str> is great for it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: