3 ms·
If you want a function to do that, you're absolutely at liberty to write one. You could even write a zero-overhead wrapper around the references to allow for o
by andrewaylett 5y ago
If you want a function to do that, you're absolutely at liberty to write one. You could even write a zero-overhead wrapper around the references to allow for overloading. Rust won't let you implement Add<&str> for &str though, you'd need to use your wrapper.
I wouldn't recommend doing that, though, and not just because of "surprise" allocations: in my experience writing Rust code, it's fairly rare to need to add strings together. I'm much more likely to use a format macro.
- couchand 5y agoAgreed, and in the cases where format! isn't up to the task, String::push_str is both easy and explicit.