mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 19:12:50 +00:00
Add another implementation example to Debug trait
This commit is contained in:
parent
f8abed9ed4
commit
1773e8318f
@ -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 `#?`:
|
||||
///
|
||||
/// ```
|
||||
|
Loading…
Reference in New Issue
Block a user