Add another implementation example to Debug trait

This commit is contained in:
Alper Çugun 2021-12-27 12:28:11 +01:00
parent f8abed9ed4
commit 1773e8318f
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -570,11 +570,26 @@ impl Display for Arguments<'_> {
/// There are a number of helper methods on the [`Formatter`] struct to help you with manual
/// implementations, such as [`debug_struct`].
///
/// [`debug_struct`]: Formatter::debug_struct
///
/// For custom cases, it's also possible to implement `Debug` using the [`write!`] macro:
/// ```
/// # 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, "Point [{} {}]", self.x, self.y)
/// }
/// }
/// ```
///
/// `Debug` implementations using either `derive` or the debug builder API
/// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`.
///
/// [`debug_struct`]: Formatter::debug_struct
///
/// Pretty-printing with `#?`:
///
/// ```