-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add another implementation example to Debug trait #92322
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
library/core/src/fmt/mod.rs
Outdated
@@ -570,8 +570,23 @@ 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` implementations using either `derive` or the debug builder API | |||
/// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`. | |||
/// For simple cases, it's also possible to implement `Debug` using the [`write!`] macro: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple vs non-simple isn't necessarily the right distinction to draw here. Standard vs non-standard is probably more like it. In other words 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this change.
library/core/src/fmt/mod.rs
Outdated
/// `Debug` implementations that have been created automatically by `derive` or implemented | ||
/// manually using a [`Formatter`] can be used by pretty-printing with the alternate flag: `{:#?}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this sentence was more meaningful the way it was prior to the PR. All Debug
implementations use a Formatter
because that's dictated by the trait signature, and generally speaking all Debug
implementations are either derived1 or manually implemented. So it's no longer clear what set of implementations is not covered by the description "created automatically by derive
or implemented manually using a Formatter
".
Footnotes
-
macro-generated ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this.
703f97f
to
1773e83
Compare
library/core/src/fmt/mod.rs
Outdated
/// # } | ||
/// | ||
/// impl fmt::Debug for Point { | ||
/// fn fmt(&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// fn fmt(&self, f: &mut fmt::Formatter <'_>) -> fmt::Result { | |
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bors r+ rollup |
📌 Commit 4df1a55 has been approved by |
…, r=dtolnay Add another implementation example to Debug trait As per the discussion in: rust-lang#92276
…, r=dtolnay Add another implementation example to Debug trait As per the discussion in: rust-lang#92276
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#92182 (Label more build steps) - rust-lang#92188 (rustdoc: Clean up NestedAttributesExt trait/implementation) - rust-lang#92322 (Add another implementation example to Debug trait) - rust-lang#92448 (Set font size proportional to user's font size) - rust-lang#92517 (Explicitly pass `PATH` to the Windows exe resolver) - rust-lang#92545 (Extract init_env_logger to crate) - rust-lang#92579 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
As per the discussion in: #92276