External Publication
Visit Post

InteriorAssign trait { a := b }

Rust Internals [Unofficial] May 11, 2026
Source

I think @Morgane55440 is saying that with the &mut self definition you could do something like this:

use std::cell::Cell;

pub trait InteriorAssign<Rhs = Self> {
    fn interior_assign(&mut self, rhs: Rhs);
}

impl<T> InteriorAssign<T> for &Cell<T> {
    fn interior_assign(&mut self, rhs: T){
        self.set(rhs);
    }
}

fn main() {
    let mut num = &Cell::new(12);
    num := 13; // (&mut num).interior_assign(13);
}

I'm not sure how the ergonomics would compare to having two separate traits, though.

Discussion in the ATmosphere

Loading comments...