diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-05 11:26:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-05 11:26:05 +0100 |
| commit | a0262fdf1f03444bdc836e9605c687377b4a82f5 (patch) | |
| tree | 061368d3a794cdcce35b686dea5b7af8f5f33ba5 | |
| parent | cc01433d56064327441ccd05100b310758a8ddbf (diff) | |
| parent | 4df1a5561adc0ee6e1635df825d34026e04530b1 (diff) | |
| download | rust-a0262fdf1f03444bdc836e9605c687377b4a82f5.tar.gz rust-a0262fdf1f03444bdc836e9605c687377b4a82f5.zip | |
Rollup merge of #92322 - alper:add_debug_trait_documentation, r=dtolnay
Add another implementation example to Debug trait As per the discussion in: #92276
| -rw-r--r-- | library/core/src/fmt/mod.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 6fc3cd0b7c4..8a2a64f8dc9 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -570,11 +570,30 @@ 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 +/// +/// Types that do not wish to use the standard suite of debug representations +/// provided by the `Formatter` trait (`debug_struct`, `debug_tuple`, +/// `debut_list`, `debug_set`, `debug_map`) can do something totally custom by +/// manually writing an arbitrary representation to the `Formatter`. +/// +/// ``` +/// # 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 `#?`: /// /// ``` |
