diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2022-03-08 15:44:52 -0500 |
|---|---|---|
| committer | Jacob Pratt <jacob@jhpratt.dev> | 2022-04-07 20:03:24 -0400 |
| commit | a3dd654ae9f9002d3ff47e45a9a9b6afcb484d2f (patch) | |
| tree | 1482d366bcee35227112579cd72d90c89a5f86fa | |
| parent | abf2b4c04d4d6a0a2c49562fde33ae1d46e6ead7 (diff) | |
| download | rust-a3dd654ae9f9002d3ff47e45a9a9b6afcb484d2f.tar.gz rust-a3dd654ae9f9002d3ff47e45a9a9b6afcb484d2f.zip | |
Add documentation
| -rw-r--r-- | library/core/src/default.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/library/core/src/default.rs b/library/core/src/default.rs index fb862f7df94..1ce00828bf3 100644 --- a/library/core/src/default.rs +++ b/library/core/src/default.rs @@ -52,6 +52,23 @@ /// 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 |
