I got confused of the example code blow of fn RefCell::borrow_mut in STD docs.
fn borrow_mut(&self) -> RefMut<'_, T>
use std::cell::RefCell;
let c = RefCell::new("hello".to_owned());
*c.borrow_mut() = "bonjour".to_owned();
assert_eq!(&*c.borrow(), "bonjour");
As RefCell::borrow_mut return a RefMut instance.
It seems the code is translated to the code blow. So the DerefMut is used to change the internal value of variable c.
Is there any explanation of thus behavior in Rust Reference or The Rust Book?
#![allow(unused)]
fn main() {
use std::cell::RefCell;
let c = RefCell::new("hello".to_owned());
{
let mut d = c.borrow_mut();
*d = "bonjour".to_owned();
}
//*c.borrow_mut() = "bonjour".to_owned();
assert_eq!(&*c.borrow(), "bonjour");
}