@@ -269,6 +269,50 @@ impl<'a> Display for Arguments<'a> {
269
269
270
270
/// Format trait for the `:?` format. Useful for debugging, all types
271
271
/// 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
272
316
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
273
317
#[ rustc_on_unimplemented = "`{Self}` cannot be formatted using `:?`; if it is \
274
318
defined in your crate, add `#[derive(Debug)]` or \
0 commit comments