About match,enum,struct.if a of Type Point,why &a match Point

I can't understand The code in the red area can run normally.

&a match EEE::Ad(p)
&a match &EEE::Ad(p)
c match Point
b match Point

The program output is as follows:
dddddd
cccccc
aaaaaa
bbbbbbb

Look at the warnings that come with the code. Point is a (capitalized) variable name here.

Regarding the EEE::Ad(…) case, that's a feature called "match ergonomics. It rewrites a pattern like EEE::Ad(p) matched against a reference into &EEE::Ad(ref p) instead of giving a compilation error, purely for programmer convenience (and to avoid the need for ref x patterns). There's a lint to disable (i. e. warn against) these, if you like.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.