From c1a89ca9d6d803d6d1889f82f1ff08541be0e9b9 Mon Sep 17 00:00:00 2001 From: Riccardo Mazzarini Date: Fri, 15 Dec 2023 13:14:56 +0100 Subject: [PATCH] refactor(types): make a few `Debug` impls easier to read --- crates/oxi-types/src/dictionary.rs | 16 +++++++++++++++- crates/oxi-types/src/object.rs | 2 +- crates/oxi-types/src/string.rs | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/oxi-types/src/dictionary.rs b/crates/oxi-types/src/dictionary.rs index e2506112..d558b894 100644 --- a/crates/oxi-types/src/dictionary.rs +++ b/crates/oxi-types/src/dictionary.rs @@ -23,7 +23,21 @@ pub(super) struct KeyValuePair { impl core::fmt::Debug for Dictionary { #[inline] fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_map().entries(self.iter()).finish() + write!(f, "{{ ")?; + + let num_elements = self.len(); + + for (idx, (key, value)) in self.iter().enumerate() { + write!(f, "{}: {:?}", key, value)?; + + if idx + 1 < num_elements { + write!(f, ", ")?; + } + } + + write!(f, " }}")?; + + Ok(()) } } diff --git a/crates/oxi-types/src/object.rs b/crates/oxi-types/src/object.rs index 4db7fe00..b224fc12 100644 --- a/crates/oxi-types/src/object.rs +++ b/crates/oxi-types/src/object.rs @@ -109,7 +109,7 @@ impl core::fmt::Debug for Object { }, }; - f.debug_tuple("Object").field(field).finish() + field.fmt(f) } } diff --git a/crates/oxi-types/src/string.rs b/crates/oxi-types/src/string.rs index 5e1c7aee..c02e7b7b 100644 --- a/crates/oxi-types/src/string.rs +++ b/crates/oxi-types/src/string.rs @@ -30,7 +30,14 @@ impl Default for String { impl core::fmt::Debug for String { #[inline] fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.write_str(self.to_string_lossy().as_ref()) + self.to_string_lossy().as_ref().fmt(f) + } +} + +impl core::fmt::Display for String { + #[inline] + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + self.to_string_lossy().as_ref().fmt(f) } }