{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiazavpx4a4dzpmkbywe5g6tt4ofsajd2m43eazalqdeaa5vd4hdiq",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgdmae7r7mv2"
  },
  "path": "/t/interior-mutability-and-safety-of-ownership-transfer-in-rust/24055#post_6",
  "publishedAt": "2026-03-05T19:18:16.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "[1]",
    "`Freeze`",
    "↩︎"
  ],
  "textContent": "ogg:\n\n> performing an “atomic” ownership switch between buffers seems intuitively sound to me,\n\nUsually one requires exclusive access with `&mut _` (e.g. any of `Vec<_>`'s potentially reallocating functions) which avoids the the question. I don't grok your approach well enough to comment much on it.\n\nogg:\n\n> It seems to me that the root cause of the problem is interior mutability. Rust does not appear to have a way to express true “read-only” types.\n\nThat is correct. There is no way to require a lack of interior mutability, or other related functionality,[1] with a bound.\n\nogg:\n\n> So I just stumbled over the unstable `Freeze` trait. This seems like a perfect trait bound for the `K` and `V` types in order to prevent data races for types with interior mutability (e.g. `HashMap<Arc<str>, AtomicUsize>`) during buffer migration.\n\nNo, `Freeze` does not guarantee there is no interior mutability in the type. It only guarantees there is no _shallow_ immutability in the inline values. There can still be interior mutability behind indirection. For example, `Box<RefCell<_>>: Freeze`.\n\nTBF, a lot of people have the same misconception. The documentation should put this clarification in flashing red lights.\n\n> internally, but not through an indirection\n\n* * *\n\n  1. using globals, using thread locals, using the FS to store state, ... ↩︎\n\n\n",
  "title": "Interior mutability and safety of ownership transfer in Rust"
}