Just because Rust pretty much forces you to be explicit about your allocations doesn't mean you have to avoid them at all costs.
Just because Rust pretty much forces you to be explicit about your allocations doesn't mean you have to avoid them at all costs.
I had almost this exact scenario, and yes there is pain in writing it with explicit lifetimes. But I can't agree the performance improvement is negligible; maybe in isolation, but I saw about a 100x speed increase for my application when I switched away from Strings. For me it was because I was doing many of those extra String allocations in a loop, so it killed my performance.
1. takes an immutable reference to a vector of strings and
2. returns an immutable reference to a string,
3. with the constraint that the strings in the input vector must not be freed before the result is freed.
It’s a reasonably concise way of saying all that.
At the end of the day, you can't understand a language without, well, learning it.