Uh oh!
There was an error while loading. Please reload this page.
Add DisplayAsDebug - A struct to help with Debug impls - #49067
Conversation
sfackler
commented
Mar 15, 2018
We can be a bit more flexible here and be generic over |
@sfackler Interesting...! so rename to |
Centril
commented
Mar 15, 2018
And now we are more flexible with |
DebugStr - A struct to help with Debug implsDebugDisplay - A struct to help with Debug implssfackler
commented
Mar 17, 2018
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. |
SimonSapin
commented
Mar 17, 2018
Bikeshed: |
sfackler
commented
Mar 17, 2018
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 implskennytm
commented
Mar 18, 2018
Why can't you use use std::fmt::{Debug,Formatter,Result};structArm<'a,L:'a,R:'a>(&'a(L,R));structTable<'a,K:'a,V:'a>(&'a[(K,V)],V);impl<'a,L:'a + Debug,R:'a + Debug>DebugforArm<'a,L,R>{fnfmt(&self,fmt:&mutFormatter) -> Result{L::fmt(&(self.0).0, fmt)?;
fmt.write_str(" => ")?;R::fmt(&(self.0).1, fmt)}}impl<'a,K:'a + Debug,V:'a + Debug>DebugforTable<'a,K,V>{fnfmt(&self,fmt:&mutFormatter) -> Result{
fmt.debug_set().entries(self.0.iter().map(Arm)).entry(&Arm(&(format_args!("{}","_"),&self.1))).finish()}}fnmain(){let table = (1..3).enumerate().collect::<Vec<_>>();assert_eq!(format!("{:?}",Table(&*table,0)),"{0 => 1, 1 => 2, _ => 0}");} |
alexcrichton
commented
Mar 18, 2018
@rfcbot concern exists Thanks @kennytm! Looks like this may already exist in libstd? |
Some thoughts:
|
SimonSapin
commented
Mar 18, 2018
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 |
dtolnay
commented
Mar 18, 2018
👍 for directing people to |
rfcbot
commented
Mar 18, 2018
@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. |
Centril
commented
Mar 18, 2018
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