If you know the total amount of bytes your final
string will take up, then use String::with_capacity()
and push_str()
. If you don't know the final
size beforehand, and you can't guesstimate at least its order of magnitude, then the above is likely equivalent with repeatedly using +
.
Some people will frown upon using +
at all, since string concatenation is conceptually different from addition, and using +
has historically resulted in bugs in other (primarily dynamically-typed) languages.
But then again, the best thing you can do is try both ways, and see if there is any difference.