Hacker News new | ask | show | jobs
by estebank 1886 days ago
There are three strategies that other languages use automatically that you can also apply in Rust by hand: string interning, small string optimization and "Copy-on-write". For the first and second, you can use some existing crate like https://docs.rs/string-interner/0.12.2/string_interner/ and https://github.com/rust-analyzer/smol_str. For the later, you can use Cow<'_, str> https://doc.rust-lang.org/std/borrow/enum.Cow.html. I'm having trouble thinking of a case where Rc<String> would be appropriate.