4 ms·
Whoa, after about 7 years of writing Rust, I only now learned that Rust's strings can be extended with `+=`. In any case, a Rust string is inherently a growabl
by dbrgn 4y ago
Whoa, after about 7 years of writing Rust, I only now learned that Rust's strings can be extended with `+=`.
In any case, a Rust string is inherently a growable data structure. It has a capacity and a size. If the size exceeds the capacity, it is reallocated.
Does Rust for Linux have "mystring.push_str(" and then we ate a whole cake,")"? If yes, why is "+=" implicit and "push_str" is not?
- tialaramex 4y agoRust's standard library String implements AddAssign, the effect of which is that the += operator exists, in effect a += b is sugar for AddAssign::add_assign(&mut a, b) Personally I would rather it didn't, but the use of + as a concatenate operator is widespread and I imagine if String didn't do this a popular BetterString would. No, the Rust for Linux String doesn't have push_str(), see for yourself: https://rust-for-linux.github.io/docs/alloc/string/struct.String.html https://rust-for-linux.github.io/docs/alloc/string/struct.St... that String also has no way to do infallible reserve(), and doesn't implement Write among other differences.