-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add DisplayAsDebug
- A struct to help with Debug impls
#49067
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
We can be a bit more flexible here and be generic over |
@sfackler Interesting...! so rename to |
And now we are more flexible with |
DebugStr
- A struct to help with Debug implsDebugDisplay
- A struct to help with Debug impls
I've written this a couple of places when I've needed to do something like this. It's a tiny little utility, but I think nice to have. @rfcbot fcp merge |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: Concerns: Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Bikeshed: |
Yeah, I was kind of thinking that an |
Totally agree with the Per discussion on #rust-libs I went with I took the liberty of making a tracking issue now so I don't have to make a commit again ^,- |
DebugDisplay
- A struct to help with Debug implsDisplayAsDebug
- A struct to help with Debug impls
Why can't you use use std::fmt::{Debug, Formatter, Result};
struct Arm<'a, L: 'a, R: 'a>(&'a (L, R));
struct Table<'a, K: 'a, V: 'a>(&'a [(K, V)], V);
impl<'a, L: 'a + Debug, R: 'a + Debug> Debug for Arm<'a, L, R> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
L::fmt(&(self.0).0, fmt)?;
fmt.write_str(" => ")?;
R::fmt(&(self.0).1, fmt)
}
}
impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for Table<'a, K, V> {
fn fmt(&self, fmt: &mut Formatter) -> Result {
fmt.debug_set()
.entries(self.0.iter().map(Arm))
.entry(&Arm(&(format_args!("{}", "_"), &self.1)))
.finish()
}
}
fn main() {
let table = (1..3).enumerate().collect::<Vec<_>>();
assert_eq!(format!("{:?}", Table(&*table, 0)),
"{0 => 1, 1 => 2, _ => 0}");
} |
@rfcbot concern exists Thanks @kennytm! Looks like this may already exist in libstd? |
Some thoughts:
|
Interesting! I think I’m now in favor of closing this RFC and either adding a new example or modifying existing examples to show this use of |
👍 for directing people to |
@dtolnay proposal cancelled. |
Team member @dtolnay has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I'll expedite the process and close the PR myself ;) |
…ug, r=steveklabnik Document format_args! / Arguments<'a> behavior wrt. Display and Debug This is a follow up PR to rust-lang#49067 , this documents the behavior of `format_args!` (i.e: `Argument<'a>`) wrt. `Display` and `Debug`.
…ug, r=steveklabnik Document format_args! / Arguments<'a> behavior wrt. Display and Debug This is a follow up PR to rust-lang#49067 , this documents the behavior of `format_args!` (i.e: `Argument<'a>`) wrt. `Display` and `Debug`. r? @steveklabnik
This adds a simple wrapper:
r? @alexcrichton