AmitKumarDas / Decisions

Apache License 2.0
10 stars 3 forks source link

Rust: Reference is automatic when you add `&` #124

Open AmitKumarDas opened 5 years ago

AmitKumarDas commented 5 years ago

:nerd_face: Dereference is done only to a referenced variable :nerd_face: A variable is automatically referenced when & is used during assignment :nerd_face: A variable can also be a reference by using the key word ref

// here the variable myref is automatically a reference
// by the virtue of &
let myref = &10;

// to test it write following code
match myref {
  &val => println!("auto referenced variable {}", val),
}

// dereference is possible only when the variable is a reference
// deference is done via *
match *myref {
  val => println!("auto referenced variable once more {}", val)
}