I know I can use derefence for a mutable reference variable to get non-reference type and I also know I can use &x to destruct a immutable reference.
fn test_destruct(&x: &i32) {
// The type of x is i32
println!("x = {}", x);
}
fn test_deref(x: &mut i32) {
// The type of *x is i32
println!("x = {}", *x);
}
fn test_desm(&mut x: &mut i32) {
// It is wrong...
// how can i destruct a mutable reference.
}
When you destructure any reference, you are essentially copying the value out of it. This is not a problem with shared references, since the value isn't mutated anyway, but if you want to operate on the value that resides behind the unique reference, you must always work through that reference.