I can use mutable reference for complicated types but not for simple data types. For example x
(u32) in myfn
:
fn main() {
let mut x: u32 = 10;
myfn(&mut x);
println!("{}", x);
}
fn myfn(x: &mut u32) {
x = 20;
//^^ expected `&mut u32`, found integer
// help: consider dereferencing here
// to assign to the mutable borrowed piece of memory
// *x = 20;
}
Is this happening because the simple type is always a copy? If so, why I can use the reference for immutable.