Yato, thanks for your response. I may be wrong, but I believe that this syntax for anonymous structs is perfectly unambiguous, as long as it only occurs in the place of a function argument type. Perhaps this requires an undesirable amount of contextual parsing, though.
Could you please provide a link to the “views” proposal your discussing? I’m not familiar with it. Or are you just talking about manually creating partial borrow structs and manually destructuring on function call?
Based on your description, it sounds like views require explicit naming. My main motivation for allowing anonymous structs here is that calling the function/method is cruft free, e.g. v3.xy_mut().
Also, if you need to use it in multiple places, you will have to name it anyways.
Not if this is implemented in the compiler frontend, where duplicate anonymous structs could be deduped.
Secondly, are these field names leaked if the fields are private, but the function is public?
Great question! That would certainly be undesirable. As a first pass, I think it would be necessary to require that the function has the same or less visibility than the least visible field. I’m not sure if anything more clever is possible, but even with this requirement I believe this syntax would be a great improvement over manually defining and using partial borrow structs.