https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ce566f2ffa3172a18ab06c9284922209
IndexMut seems possible thanks to get_mut() on the Cell. This is allowed, because all the &muts require exclusive access.
However, I’m surprised that IndexMut requires existence of Index.
And Index is not possible. This is because Cell allows shared mutable access as long as its done via .set(). However, if it exposed shared reference to its contents, another call to .set() could change value of the shared immutable reference. Rust can’t allow that.
&self.data[index].get()
doesn’t compile, because it’s equivalent of:
let tmp = self.data[index].get(); // it's a *copy* that lives on stack
return &tmp; // the stack variable will be destroyed before the function returns
Rust doesn’t have traits for indexing that set or return things by value. I’m not sure why.