Hi, there's this site
The code that I don't understand is this
fn main() {
// Assign a reference of type `i32`. The `&` signifies there
// is a reference being assigned.
let reference = &4;
match reference {
// If `reference` is pattern matched against `&val`, it results
// in a comparison like:
// `&i32`
// `&val`
// ^ We see that if the matching `&`s are dropped, then the `i32`
// should be assigned to `val`.
&val => println!("Got a value via destructuring: {:?}", val),
}
I don't understand why it is presented. Is it solely for the purpose to show differences between destructuring and dereferencing, or can this code pattern be used in real programs?
When I change &4 to 4 I get a different outcome at compile time, an error, so I can't use that kind of code to do some sort of RTTI. I believe I could do some sort of RTTI by using a cast and None and Some, that is in another example.
So, if that code can only destructure, is it maybe the only way to destructure? Isn't it too long for that?
So....it's "demo code" that demonstrates a difference, but it's impossible to really make use of this code, or is it?