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 5252/// This trait can be used with `#[derive]` if all of the type's fields implement
5353/// `Default`. When `derive`d, it will use the default value for each field's type.
5454///
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+ ///
5572/// ## How can I implement `Default`?
5673///
5774/// Provide an implementation for the `default()` method that returns the value of
You can’t perform that action at this time.
0 commit comments