File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 52
52
/// This trait can be used with `#[derive]` if all of the type's fields implement
53
53
/// `Default`. When `derive`d, it will use the default value for each field's type.
54
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
+ ///
55
72
/// ## How can I implement `Default`?
56
73
///
57
74
/// Provide an implementation for the `default()` method that returns the value of
You can’t perform that action at this time.
0 commit comments