Skip to content

Commit bd50eff

Browse files
committed
Make the Default docs more like the other traits
Add explicit "Derivable" and "How can I implement `Default`" sections. Copied relevant sections from the module-level documentation, but also linked to there-- it has a more comprehensive narrative with examples that show implementation AND use. Decided to just put implementation example in the trait documentation.
1 parent 8b00a08 commit bd50eff

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/libcore/default.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,33 @@
8484

8585
use marker::Sized;
8686

87-
/// A trait for giving a type a useful default value.
87+
/// A trait for giving a type a useful default value. For more information, see
88+
/// [the module-level documentation][module].
8889
///
89-
/// A struct can derive default implementations of `Default` for basic types using
90-
/// `#[derive(Default)]`.
90+
/// [module]: ../../std/default/index.html
91+
///
92+
/// ## Derivable
93+
///
94+
/// This trait can be used with `#[derive]` if all of the type's fields implement
95+
/// `Default`. When `derive`d, it will use the default value for each field's type.
96+
///
97+
/// ## How can I implement `Default`?
98+
///
99+
/// Provide an implementation for the `default()` method that returns the value of
100+
/// your type that should be the default:
101+
///
102+
/// ```
103+
/// # #![allow(dead_code)]
104+
/// enum Kind {
105+
/// A,
106+
/// B,
107+
/// C,
108+
/// }
109+
///
110+
/// impl Default for Kind {
111+
/// fn default() -> Kind { Kind::A }
112+
/// }
113+
/// ```
91114
///
92115
/// # Examples
93116
///

0 commit comments

Comments
 (0)