Uh oh!
There was an error while loading. Please reload this page.
Add key and value methods to DebugMap - #60458
Conversation
rust-highfive
commented
May 1, 2019
Some changes occurred in HTML/CSS. |
rust-highfive
commented
May 1, 2019
r? @rkruppe (rust_highfive has picked a reviewer for you, use r? to override) |
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Shifting the state of the PadAdapter into a dedicated struct here lets value pick up where key left off without having to guess what the state was before.
GuillaumeGomez
commented
May 2, 2019
@rust-lang/infra: seems like a condition is broken:
|
emilyalbini
commented
May 2, 2019
Highfive is working as expected though: |
GuillaumeGomez
commented
May 2, 2019
Ah indeed! My bad. |
KodrAus
commented
May 13, 2019
Very quick, very dirty benchmark: #![feature(test)]externcrate test;use std::{
cell::Cell,
fmt::{self,Write},};structNoOpWrite;implWriteforNoOpWrite{fnwrite_str(&mutself, _:&str) -> fmt::Result{Ok(())}}#[bench]fndebugmap_entry(b:&mut test::Bencher){structMap<'a>(Cell<Option<&'amut test::Bencher>>);impl<'a> fmt::DebugforMap<'a>{fnfmt(&self,f:&mut fmt::Formatter) -> fmt::Result{letmut map = f.debug_map();let b = self.0.take().unwrap();
b.iter(|| {
map.entry(&"a",&42);});
map.finish()}}let _ = write!(NoOpWrite,"{:?}",Map(Cell::new(Some(b))));}On my machine, running this on the current
So there's a bit of a performance impact like you'd expect, but I don't think it's too significant, and if it is we can inline the implementation in |
KodrAus
commented
May 17, 2019
This comment has been minimized.
This comment has been minimized.
alexcrichton
commented
May 20, 2019
This all looks great to me! I think this is still waiting on the RFC, though, right? (FWIW I wouldn't personally consider this as requiring an RFC, but I don't mind waiting if one's open!) |
KodrAus
commented
May 22, 2019
Thanks! Yeh, there's an RFC for this at the moment, so I'm also happy to let this sit and wait on that. |
KodrAus
commented
Jul 7, 2019
Alrighty, the RFC has been merged and I've updated the stability attributes to point to the tracking issue. I think this should be ready to go now! |
alexcrichton
commented
Jul 8, 2019
r=me, thanks! Looks like CI may be failing though? |
KodrAus
commented
Jul 9, 2019
Looks like we're all good! @bors r=alexcrichton |
Centril
commented
Jul 9, 2019
@bors r=alexcrichton |
bors
commented
Jul 9, 2019
📌 Commit 70d630f has been approved by |
…hton Add key and value methods to DebugMap Implementation PR for an active (not approved) RFC: rust-lang/rfcs#2696. Add two new methods to `std::fmt::DebugMap` for writing the key and value part of a map entry separately: ```rust impl<'a, 'b: 'a> DebugMap<'a, 'b> { pub fn key(&mut self, key: &dyn Debug) -> &mut Self; pub fn value(&mut self, value: &dyn Debug) -> &mut Self; } ``` I want to do this so that I can write a `serde::Serializer` that forwards to our format builders, so that any `T: Serialize` can also be treated like a `T: Debug`.
Rollup of 4 pull requests Successful merges: - #60458 (Add key and value methods to DebugMap) - #62090 (typeck: merge opaque type inference logic) - #62403 (Replace SliceConcatExt trait with inherent methods and SliceConcat helper trait) - #62494 (Remove unused dependencies) Failed merges: r? @ghost
Implementation PR for an active (not approved) RFC: rust-lang/rfcs#2696.
Add two new methods to
std::fmt::DebugMapfor writing the key and value part of a map entry separately:I want to do this so that I can write a
serde::Serializerthat forwards to our format builders, so that anyT: Serializecan also be treated like aT: Debug.