News for hackers. Stuff that matters.
Re:Fast Rust Builds by lenkite on Monday September 06, 2021 @04:29AM (#28431634)
I never understood why Rust requires '&mut' while passing parameters.

        file.read_to_end(&mut bytes)?;
`bytes` is already mutable. `read_to_end` is already declared as taking a `&mut Vec<u8>`. So why force every caller to do a `&mut` un-necessarily ?
Re:Fast Rust Builds by MathiasPius on Monday September 06, 2021 @04:51AM (#28431725)
It's so that a reader of the calling code can immediately reason about which calls might be mutating state. If you have 10 calls, all taking &bytes, any of which may or may not be mutating the data while others are merely reading it, it becomes very difficult to reason about.

By being explicit about this, Rust becomes easier to read, but (slightly) harder to write.

Re:Fast Rust Builds by zozbot234 on Monday September 06, 2021 @05:32AM (#28431950)
Shared borrows and unique borrows also behave very differently in Rust. '&mut' for unique borrows is a bit of a misnomer, because passing some objects via a shared '&' reference might also mutate state 'indirectly' via internal mutability.
Re:Fast Rust Builds by masklinn on Monday September 06, 2021 @11:15AM (#28434495)
> So why force every caller to do a `&mut` un-necessarily ?

Because it's not unnecessary? `bytes` is a `Vec`, not a `&mut Vec`, those are different things, and Rust generally avoids magically doing things under the covers. So it doesn't auto-ref (let alone auto-mut-ref) parameters, only subjects.