Skip to content

Commit a3dd654

Browse files
committed
Add documentation
1 parent abf2b4c commit a3dd654

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

library/core/src/default.rs

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@
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

0 commit comments

Comments
 (0)