I was surprised to see the smart pointer RefCell can mutate any type of data as I expect to mutate even const. Why const data cannot be mutated via smart pointers? If I considered the const can never be changed then why the attempt to modify const data executed successfully?
const NAME : RefCell<&str> = RefCell::new("XYZ");
println!("The const NAME is: {}",*NAME.borrow_mut());
*NAME.borrow_mut() = "abc";
println!("The mutated NAME is: {}",*NAME.borrow());
I exactly want to know why the const data is not modified even the compiler executed the code successfully. I expect the compiler will stop me from doing that modification but actually it didn't? Here is the output,
The name is: XYZ
The mutated name is: XYZ