From bd50effe0f3c030c47cd444888426a82c589f9fa Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Sun, 22 May 2016 19:24:58 -0400 Subject: [PATCH] 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. --- src/libcore/default.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/libcore/default.rs b/src/libcore/default.rs index 12c4a5ca200a..74101c66c97a 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -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 ///