-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Proposal
Summary and problem statement
Support instantiation of non-exhaustive structs outside their defining crate
if they use functional update syntax with a base (e.g. ..Default::default()
).
Motivation, use-cases, and solution sketches
Modifying core structs requires code changes everywhere in a code base where
those structs are constructed. Often in libraries, construction is
abstracted by constructor methods and this isn't a huge concern. However, structs
used as part of serialization or communication, for example, are often
plain-old-data style types and are constructed directly. It would be nice if
these kinds of structs could undergo certain modifications without requiring
downstream code changes everywhere they are created. #[non_exhaustive]
attributes on structs allow such modification but then prohibit construction
outside of the defining crate.
This proposal would allow construction of #[non_exhaustive]
structs if the
construction uses the functional update syntax from a suitable base such as
..Default::default()
. This would allow construction outside the defining
crate and require no code changes when common modifications are made such as
adding a new field with a default value.
Links and related work
None
Initial people involved
- Owner, if known: metajack?
- Liaison
What happens now?
This issue is part of the lang-team initiative process. Once this issue is filed, a Zulip topic will be opened for discussion, and the lang-team will review open proposals in its weekly triage meetings. You should receive feedback within a week or two.
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.