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.
This commit is contained in:
Carol (Nichols || Goulding) 2016-05-22 19:24:58 -04:00
parent 8b00a086e7
commit bd50effe0f

View file

@ -84,10 +84,33 @@
use marker::Sized;
/// A trait for giving a type a useful default value.
/// A trait for giving a type a useful default value. For more information, see
/// [the module-level documentation][module].
///
/// A struct can derive default implementations of `Default` for basic types using
/// `#[derive(Default)]`.
/// [module]: ../../std/default/index.html
///
/// ## Derivable
///
/// 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.
///
/// ## How can I implement `Default`?
///
/// Provide an implementation for the `default()` method that returns the value of
/// your type that should be the default:
///
/// ```
/// # #![allow(dead_code)]
/// enum Kind {
/// A,
/// B,
/// C,
/// }
///
/// impl Default for Kind {
/// fn default() -> Kind { Kind::A }
/// }
/// ```
///
/// # Examples
///