Pre-RFC: User-provided default field values

I think I finally understood: the language needs three kinds of structs:

  1. cannot be constructed outside own crate so that

    • new private or
    • pub fields w/o defaults can be added
      and this is not a breaking change
  2. can be constructed outside own crate
    using the current S{a : b} syntax
    but adding new fields is a breaking change

  3. can be constructed outside own create
    using the new S{a : b, ..} syntax
    but adding new fields without defaults is a breaking change

Currently Rust only has (1) and (2) which are distinguished via non_exhaustive. But there is no way around it is there? Kind number (3) has to be provided, right? And it has to be marked somehow.

1 Like