Rust is a novice rookie. I began to learn this young language just a few days ago, and I have been learning it for almost half a week.
I have to say that there are many things I don"t quite understand about the syntax of Rust, and the threshold for entry is higher than that of other languages.
such as this question.
Code 1:
let mut num1 = 1000;
let mut num2 = &mut num1;
println!("{}",num2);
*num2 += 100;
println!("{}",num2);
the output is as follows:
1000
1100
as expected, num2 is a pointer to num1.
Code 2:
let mut op = Some(100);
match op {
None => {}
Some(mut x) => {
let mut change = &mut x;
*change += 1000;
println!("{:?}",*change);
}
}
println!("{:?}",op);
according to my understanding of match, I think the
here Some(mut x) => {....}
is equivalent to
let mut x = ....
The type of x should be a & mut i32
then the type of change should be & mut & mut i32 = > & mut i32
and the output is
1100
Some(100)
Why can the change on the inside be changed, but the op on the outside remain the same? shouldn"t they be the same address?
what does the match keyword do with the following variables if it is not the same address?
welcome to discuss.