This Pre-RFC is to suggest the allowance of associated structs, enums and traits to be defined in structs, enums and traits.
Movitation
Currently if we have to write a struct which has a property which is another struct, enum or trait, we would have to write the following (the following example uses a struct + enum for demonstration of how we write this currently):
Visibility modifiers can also be applied to the associated structs, enums or traits.
For private associated structs/enums/traits within the types, maybe (?) the following can be added?
pub(in struct)
pub(in enum)
pub(in trait)
Design
This change will require the acceptance of associated structs, enums and traits inside a struct, enum or trait. However, there are some syntax rules I propose about the feature:
A semicolon is required to show that the usual declaration of the struct or enum has ended before writing the associated struct, enum or trait;
For traits, they can be declared anywhere as long as it is ended with a ;.
Alternatives
Feel free to suggest some alternatives to this (even though I did not come up with any for now)!
I just reviewed the structural records RFC and see that it's now in FCP to be closed, alas. In the process they noted that RFC 2102 was accepted, but that's even more limited in scope (FFI with C is the motivation).
I think it would make more sense for the associated structs/enums/traits to be nested in an inherent impl block for the parent type since that's where rust already supports items:
Even though we can add associated type aliases, I still feel that it is kind of redundant when there's a possibility to declare associated structs/enums/traits inside a declaration or inherent impl.