Hacker News new | ask | show | jobs
by microtonal 2618 days ago
E.g. since immutable references are the default, you immediately know whether or not a call will modify its argument.

You do not, since the type of which an object is referenced could use interior mutability (e.g. RefCell). So, you only know if this is the case after inspecting the type.

Of course, the default in Rust is to use exterior mutability and in general, interior mutability is/should be avoided.

(I agree with the general thrust of your comment though.)

1 comments

Rust's mutable/immutable is better thought of as exclusive/shared. But in any case, the interior mutability is not causing problems, because the compiler still largely enforces it's used correctly (e.g. no matter how deeply RefCell is hidden, code using it won't be able to share it with another thread, so you don't need to worry about getting a data race this way).