Skip to content

Commit 1773e83

Browse files
committed
Add another implementation example to Debug trait
1 parent f8abed9 commit 1773e83

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Diff for: library/core/src/fmt/mod.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,26 @@ impl Display for Arguments<'_> {
570570
/// There are a number of helper methods on the [`Formatter`] struct to help you with manual
571571
/// implementations, such as [`debug_struct`].
572572
///
573+
/// [`debug_struct`]: Formatter::debug_struct
574+
///
575+
/// For custom cases, it's also possible to implement `Debug` using the [`write!`] macro:
576+
/// ```
577+
/// # use std::fmt;
578+
/// # struct Point {
579+
/// # x: i32,
580+
/// # y: i32,
581+
/// # }
582+
///
583+
/// impl fmt::Debug for Point {
584+
/// fn fmt(&self, f: &mut fmt::Formatter <'_>) -> fmt::Result {
585+
/// write!(f, "Point [{} {}]", self.x, self.y)
586+
/// }
587+
/// }
588+
/// ```
589+
///
573590
/// `Debug` implementations using either `derive` or the debug builder API
574591
/// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`.
575592
///
576-
/// [`debug_struct`]: Formatter::debug_struct
577-
///
578593
/// Pretty-printing with `#?`:
579594
///
580595
/// ```

0 commit comments

Comments
 (0)