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:
parent
8b00a086e7
commit
bd50effe0f
1 changed files with 26 additions and 3 deletions
|
|
@ -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
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue