about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-29 08:40:20 +0000
committerbors <bors@rust-lang.org>2015-05-29 08:40:20 +0000
commitb9eb606801067ef2994d9667e7f424fb331143ab (patch)
tree9eed3b2477ded2500226005b02a35b09b0826f68 /src/libcore
parent25fc917c65f7c51fafdab0f023772171f84c7f0a (diff)
parent977d40fbfad4e36f1d264396b11b8b06f9ac921d (diff)
downloadrust-b9eb606801067ef2994d9667e7f424fb331143ab.tar.gz
rust-b9eb606801067ef2994d9667e7f424fb331143ab.zip
Auto merge of #25830 - steveklabnik:debug_docs, r=alexcrichton
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/fmt/mod.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index da873f76d1b..ee1cab4076d 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -269,6 +269,50 @@ impl<'a> Display for Arguments<'a> {
 
 /// Format trait for the `:?` format. Useful for debugging, all types
 /// should implement this.
+///
+/// Generally speaking, you should just `derive` a `Debug` implementation.
+///
+/// # Examples
+///
+/// Deriving an implementation:
+///
+/// ```
+/// #[derive(Debug)]
+/// struct Point {
+///     x: i32,
+///     y: i32,
+/// }
+///
+/// let origin = Point { x: 0, y: 0 };
+///
+/// println!("The origin is: {:?}", origin);
+/// ```
+///
+/// Manually implementing:
+///
+/// ```
+/// use std::fmt;
+///
+/// struct Point {
+///     x: i32,
+///     y: i32,
+/// }
+///
+/// impl fmt::Debug for Point {
+///     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+///         write!(f, "({}, {})", self.x, self.y)
+///     }
+/// }
+///
+/// let origin = Point { x: 0, y: 0 };
+///
+/// println!("The origin is: {:?}", origin);
+/// ```
+///
+/// There are a number of `debug_*` methods on `Formatter` to help you with manual
+/// implementations, such as [`debug_struct`][debug_struct].
+///
+/// [debug_struct]: ../std/fmt/struct.Formatter.html#method.debug_struct
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \
                             defined in your crate, add `#[derive(Debug)]` or \