We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent abf2b4c commit a3dd654Copy full SHA for a3dd654
library/core/src/default.rs
@@ -52,6 +52,23 @@
52
/// This trait can be used with `#[derive]` if all of the type's fields implement
53
/// `Default`. When `derive`d, it will use the default value for each field's type.
54
///
55
+/// ### `enum`s
56
+///
57
+/// When using `#[derive(Default)]` on an `enum`, you need to choose which unit variant will be
58
+/// default. You do this by placing the `#[default]` attribute on the variant.
59
60
+/// ```
61
+/// #[derive(Default)]
62
+/// enum Kind {
63
+/// #[default]
64
+/// A,
65
+/// B,
66
+/// C,
67
+/// }
68
69
70
+/// You cannot use the `#[default]` attribute on non-unit or non-exhaustive variants.
71
72
/// ## How can I implement `Default`?
73
74
/// Provide an implementation for the `default()` method that returns the value of
0 commit comments