1. 6
    1. 5

      Of course “break” here is not meant literally. All of this works exactly as designed, and still upholds all safety guarantees.

      It’s important to remember that Rust’s references aren’t mutable/immutable, but exclusive/shared. It is perfectly fine to mutate data via a shared reference, as long as something ensures it’s still safe (e.g mutex or atomic).

      1. 4

        Yeah I don’t like the title here much. The rules here aren’t being broken, they’re being enforced at runtime rather than compile time.

      2. 1

        I do with rust had true immutable more easily. I think it was intended to be mutable/imutable at some point but they changed their minds…

        1. 2

          Rust has changed a lot before 1.0. Earliest versions were even supposed to have a per-thread GC!

          But current Rust has a tension between what its memory model really is, and what programmers expect it to be. The prime example is the mut keyword in bindings (let mut): it doesn’t do anything for the memory model. It’s a meaningless talisman. In Rust every owned object is always mutable, but people strongly dislike that, expecting immutable objects or immutable variables to exist. So Rust has a lint that weakly fakes immutable objects, and requires you to add and remove mut to pretend so (not to be confused with &mut which is important and strongly enforced)

      3. 1

        That perspective makes a lot of sense. Is there somewhere I can read more about it?

        1. 1

          Rust calls it “interior mutability”, and there’s UnsafeCell type for making primitives that “break” the borrow checker. The fine details of actual exclusivity rules are still a work in progress, but Stacked Borrows is the current candidate.

    2. 2

      This is very well written. The motivation for each construct introduced (Rc, Arc, RefCell, Mutex, RwLock) is clear throughout. I’ve learned a lot today!

    3. 1

      Completely off topic, but why do so many people use GitHub Gist embeds for code snippets? Is it the easiest way for them to get syntax highlighted code into their post? It seems like overly complex and high friction, or does the blogging software integrate well here?