-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: syntax for specifying properties for struct fields #35795
Comments
This looks to me like it would make |
This is reserved but not implemented struct A
x::Int = 1
end Those are not implemented but could be clean too to reach some metatype / datatype struct A
x::Int => (u, v=(1, 2)) # meta properties thru pairs
end struct A
x where {u=true, v=(1, 2)} # meta properties thru where clause fields
end |
fwiw, go has struct field "tags" (ref) that are convenient for attaching properties to fields, like certain JSON properties (e.g. |
As does rust: https://serde.rs/attributes.html (Although I wouldn’t try to copy the syntax.) |
dotnet has attribute , something similar to rust. hot points that need to be handled: composition % ordering, interweaving with the lowerer, data storage & type caps, etc. |
We've have some open design questions from the past (#22649, #20415, #9448) of wanting to attach some properties to various fields of an object. Separately, while doing other work (and having need of this now), I ended up stumbling across a syntax that I feel I liked for this. It already parses, but currently has no meaning during lowering. To me, this looks like a parenthetical that describes the field, which is indeed what it is!
So, without further ado, here I show a random example struct (the actual names are nonsense), and apply various keyword attributes to some of the fields (also nonsense, but just to show some possibilities for how this could be used/useful):
Thoughts? Reactions?
The text was updated successfully, but these errors were encountered: