Re:Identifying Rust's collect:<Vec<_>>() memory leak footgun
by ironhaven on Thursday January 18, 2024 @01:27PM
(#39045556)
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
[ Parent
| on HN ]
Re:Identifying Rust's collect:<Vec<_>>() memory leak footgun
by zozbot234 on Thursday January 18, 2024 @01:40PM
(#39045785)
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.
Re:Identifying Rust's collect:<Vec<_>>() memory leak footgun
by bobbylarrybobby on Thursday January 18, 2024 @03:36PM
(#39047317)
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.
Re:Identifying Rust's collect:<Vec<_>>() memory leak footgun
by steveklabnik on Thursday January 18, 2024 @04:23PM
(#39047957)
Yeah, the general concept here is https://en.wikipedia.org/wiki/String_interning, Box<str> is great for it.