@@ -278,8 +278,8 @@ as well.
278
278
# Detailed design
279
279
280
280
An attribute ` #[non_exhaustive] ` is added to the language, which will (for now)
281
- fail to compile if it's used on anything other than an enum, struct definition,
282
- or enum variant.
281
+ fail to compile if it's used on anything other than an enum or struct
282
+ definition, or enum variant.
283
283
284
284
## Enums
285
285
@@ -417,6 +417,10 @@ Then we the only valid way of matching will be:
417
417
let Config { 0 : width , 1 : height , .. } = config ;
418
418
```
419
419
420
+ We can think of this as lowering the visibility of the constructor to
421
+ ` pub(crate) ` if it is marked as ` pub ` , then applying the standard structure
422
+ rules.
423
+
420
424
## Unit structs
421
425
422
426
Unit structs will work very similarly to tuple structs. Consider this struct:
@@ -433,6 +437,41 @@ match it like:
433
437
let Unit { .. } = unit ;
434
438
```
435
439
440
+ To users of this crate, this will act exactly as if the struct were defined as:
441
+
442
+ ```
443
+ #[non_exhaustive]
444
+ pub struct Unit {}
445
+ ```
446
+
447
+ ## Functional record updates
448
+
449
+ Functional record updates will operate exactly the same regardless of whether
450
+ structs are marked as non-exhaustive or not. For example, given this struct:
451
+
452
+ ```
453
+ #[derive(Debug)]
454
+ #[non_exhaustive]
455
+ pub struct Config {
456
+ pub width: u16,
457
+ pub height: u16,
458
+ pub fullscreen: bool,
459
+ }
460
+ impl Default for Config {
461
+ fn default() -> Config {
462
+ Config { width: 640, height: 480, fullscreen: false }
463
+ }
464
+ }
465
+ ```
466
+
467
+ The below code will print `Config { width: 1920, height: 1080, fullscreen:
468
+ false }` regardless of which crate is calling it:
469
+
470
+ ```
471
+ let c = Config { width: 1920, height: 1080, ..Config::default() };
472
+ println!("{:?}", c);
473
+ ```
474
+
436
475
## Changes to rustdoc
437
476
438
477
Right now, the only indicator that rustdoc gives for non-exhaustive enums and
0 commit comments