]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/default.rs
Auto merge of #94598 - scottmcm:prefix-free-hasher-methods, r=Amanieu
[rust.git] / library / core / src / default.rs
index fb862f7df947bc5d688cf1bb46446a8de968ffee..1ce00828bf3449c248c12b5a3f18ff07a62dab48 100644 (file)
 /// This trait can be used with `#[derive]` if all of the type's fields implement
 /// `Default`. When `derive`d, it will use the default value for each field's type.
 ///
+/// ### `enum`s
+///
+/// When using `#[derive(Default)]` on an `enum`, you need to choose which unit variant will be
+/// default. You do this by placing the `#[default]` attribute on the variant.
+///
+/// ```
+/// #[derive(Default)]
+/// enum Kind {
+///     #[default]
+///     A,
+///     B,
+///     C,
+/// }
+/// ```
+///
+/// You cannot use the `#[default]` attribute on non-unit or non-exhaustive variants.
+///
 /// ## How can I implement `Default`?
 ///
 /// Provide an implementation for the `default()` method that returns the value of