3 ms·
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 ide
by ironhaven 3y ago
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
- zozbot234 3y agoArc<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.
- bobbylarrybobby 3y agoBox<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.
- steveklabnik 3y agoYeah, the general concept here is https://en.wikipedia.org/wiki/String_interning https://en.wikipedia.org/wiki/String_interning, Box<str> is great for it.