Skip to content

Commit

Permalink
feat!: use Formatter::debug_{map,set} instead of hand-written outer…
Browse files Browse the repository at this point in the history
… `Debug` structure

This actually supports pretty-printing with the alternate flag `:#`,
which is surely intended.

It should be noted that pretty-printing can be significantly slower than
using "plain" `Debug` printing. Performance-sensitive users that desire
to keep the "fast" printing behavior should avoid specifying `{:#?}` for
their `GenericPatriciaMap`s and `GenericPatriciaSet`s.
  • Loading branch information
ErichDonGubler committed Oct 25, 2023
1 parent ce8f731 commit dd57650
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
10 changes: 1 addition & 9 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,15 +491,7 @@ impl<K: Bytes, V> GenericPatriciaMap<K, V> {
}
impl<K: Bytes + fmt::Debug, V: fmt::Debug> fmt::Debug for GenericPatriciaMap<K, V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{")?;
for (i, (k, v)) in self.iter().enumerate() {
if i != 0 {
write!(f, ", ")?;
}
write!(f, "{:?}: {:?}", k, v)?;
}
write!(f, "}}")?;
Ok(())
f.debug_map().entries(self.iter()).finish()
}
}
impl<K, V: Clone> Clone for GenericPatriciaMap<K, V> {
Expand Down
10 changes: 1 addition & 9 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,7 @@ impl<T: Bytes> GenericPatriciaSet<T> {
}
impl<T: Bytes + fmt::Debug> fmt::Debug for GenericPatriciaSet<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{{")?;
for (i, t) in self.iter().enumerate() {
if i != 0 {
write!(f, ", ")?;
}
write!(f, "{:?}", t)?;
}
write!(f, "}}")?;
Ok(())
f.debug_set().entries(self.iter()).finish()
}
}
impl<T> Clone for GenericPatriciaSet<T> {
Expand Down

0 comments on commit dd57650

Please sign in to comment.