0

All the commented lines below are valid. How do multiple & have the same impact? Does Rust do some magic to interpret multiple &s?

// All commented code is also valid - wondering how?
let string_a = String::from("String A");
let str_a: &str = &string_a;
// let str_a: &str = &&&&&string_a; // --> this is valid statement

let mut str_option: Option<&str>;
str_option = Some(str_a);
// str_option = Some(&str_a);  // --> this is valid statement
// str_option = Some(&&str_a); // --> this is also valid statement
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Ujash
  • 1
  • 2
  • 1
    Does [this](https://stackoverflow.com/questions/28519997/what-are-rusts-exact-auto-dereferencing-rules) answer your question? – mcarton Aug 04 '20 at 18:50
  • 1
    Or [this](https://stackoverflow.com/questions/53341819/what-is-the-relation-between-auto-dereferencing-and-deref-coercion)? – mcarton Aug 04 '20 at 18:51
  • 1
    Thank you! @mcarton these answers my question. – Ujash Aug 05 '20 at 13:58

0 Answers0