Skip to content

Commit b42ea50

Browse files
authored
Rollup merge of rust-lang#92322 - alper:add_debug_trait_documentation, r=dtolnay
Add another implementation example to Debug trait As per the discussion in: rust-lang#92276
2 parents 2e0b081 + 4df1a55 commit b42ea50

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

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

+21-2
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,30 @@ 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+
/// Types that do not wish to use the standard suite of debug representations
576+
/// provided by the `Formatter` trait (`debug_struct`, `debug_tuple`,
577+
/// `debut_list`, `debug_set`, `debug_map`) can do something totally custom by
578+
/// manually writing an arbitrary representation to the `Formatter`.
579+
///
580+
/// ```
581+
/// # use std::fmt;
582+
/// # struct Point {
583+
/// # x: i32,
584+
/// # y: i32,
585+
/// # }
586+
/// #
587+
/// impl fmt::Debug for Point {
588+
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
589+
/// write!(f, "Point [{} {}]", self.x, self.y)
590+
/// }
591+
/// }
592+
/// ```
593+
///
573594
/// `Debug` implementations using either `derive` or the debug builder API
574595
/// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`.
575596
///
576-
/// [`debug_struct`]: Formatter::debug_struct
577-
///
578597
/// Pretty-printing with `#?`:
579598
///
580599
/// ```

0 commit comments

Comments
 (0)