Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Reference patterns might not always be irrefutable?

Reference patterns are always irrefutable.

source

The reference show this code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let int_reference = &3;

let a = match *int_reference { 0 => "zero", _ => "some" };
let b = match int_reference { &0 => "zero", _ => "some" };

assert_eq!(a, b);

If reference patterns would be irrefutable, then the _ => "some" arm would never execute since &0 is irrefutable and matching anything, but of course this is not true.

It seems like for me is that reference pattern is only irrefutable if the subpattern is irrefutable. For example &x (identifier pattern) would be indeed irrefutable since x is irrefutable.

Am I right or am I missing something?

>Solution :

You are correct. Reference patterns by themselves are irrefutable, but other parts of the whole pattern may be refutable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading