Skip to content

Commit b9eb606

Browse files
committed
Auto merge of #25830 - steveklabnik:debug_docs, r=alexcrichton
2 parents 25fc917 + 977d40f commit b9eb606

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/libcore/fmt/mod.rs

+44
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,50 @@ impl<'a> Display for Arguments<'a> {
269269

270270
/// Format trait for the `:?` format. Useful for debugging, all types
271271
/// should implement this.
272+
///
273+
/// Generally speaking, you should just `derive` a `Debug` implementation.
274+
///
275+
/// # Examples
276+
///
277+
/// Deriving an implementation:
278+
///
279+
/// ```
280+
/// #[derive(Debug)]
281+
/// struct Point {
282+
/// x: i32,
283+
/// y: i32,
284+
/// }
285+
///
286+
/// let origin = Point { x: 0, y: 0 };
287+
///
288+
/// println!("The origin is: {:?}", origin);
289+
/// ```
290+
///
291+
/// Manually implementing:
292+
///
293+
/// ```
294+
/// use std::fmt;
295+
///
296+
/// struct Point {
297+
/// x: i32,
298+
/// y: i32,
299+
/// }
300+
///
301+
/// impl fmt::Debug for Point {
302+
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
303+
/// write!(f, "({}, {})", self.x, self.y)
304+
/// }
305+
/// }
306+
///
307+
/// let origin = Point { x: 0, y: 0 };
308+
///
309+
/// println!("The origin is: {:?}", origin);
310+
/// ```
311+
///
312+
/// There are a number of `debug_*` methods on `Formatter` to help you with manual
313+
/// implementations, such as [`debug_struct`][debug_struct].
314+
///
315+
/// [debug_struct]: ../std/fmt/struct.Formatter.html#method.debug_struct
272316
#[stable(feature = "rust1", since = "1.0.0")]
273317
#[rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \
274318
defined in your crate, add `#[derive(Debug)]` or \

0 commit comments

Comments
 (0)