{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreibaorhs3ubqlkk46jpybdtr6b7ckbztywoski7sknfr5ly623oloa",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mlj44uzxija2"
  },
  "path": "/t/interiorassign-trait-a-b/24291#post_1",
  "publishedAt": "2026-05-10T14:42:44.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "There are already traits such as `AddAssign` to implement `+=`.\n\nIt would be useful for code clarity if you could implement `InteriorAssign` to use `:=`.\n\nThis could be used to sugar syntax such as this:\n\n`data.ref_cell.replace(Some(new_value))`\n\ninto this:\n\n`data.ref_cell := Some(new_value)`\n\nWhich I personally find easier to read. And there is no ambiguity with `=`\n\n* * *\n\nThe trait could look something like this:\n\n\n    pub trait InteriorAssign<Rhs = Self> {\n        fn assign(&self, rhs: Rhs);\n    }\n\n\nNote the `&self` to allow this to be used for interior immutability.\n\n* * *\n\nThere could be `InteriorOpAssign` versions that use `&self` for all the other operators as well:\n\n`InteriorAddAssign` => `:+=`\n\n`InteriorSubAssign` => `:-=`\n\nEtc...\n\n* * *\n\n# Bonus\n\nAs a bonus, (I'm not sure this can work) implement `InteriorAccess` to use `->`\n\nSo instead of:\n\n`ref_cell.borrow_mut().some_method()`\n\nYou can use:\n\n`ref_cell->some_method()`\n\nIt might cause issues for the parser because it is used for function returns, but if not then this syntax could cut down a lot on a lot of boilerplate working with interior mutability.\n\nOther symbol options:\n\n`ref_cell~>some_method()`\n\n`ref_cell:.some_method()`\n\n`ref_cell:->some_method()`",
  "title": "InteriorAssign trait { a := b }"
}