News for hackers. Stuff that matters.
Re:A pair of Rust kernel modules by dbrgn on Friday September 23, 2022 @10:53AM (#32952745)
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?

Re:A pair of Rust kernel modules by tialaramex on Friday September 23, 2022 @12:25PM (#32954001)
Rust'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.St... that String also has no way to do infallible reserve(), and doesn't implement Write among other differences.