Skip to content

Commit

Permalink
refactor(types): make a few Debug impls easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 15, 2023
1 parent 4eab70f commit c1a89ca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 15 additions & 1 deletion crates/oxi-types/src/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxi-types/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl core::fmt::Debug for Object {
},
};

f.debug_tuple("Object").field(field).finish()
field.fmt(f)
}
}

Expand Down
9 changes: 8 additions & 1 deletion crates/oxi-types/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit c1a89ca

Please sign in to comment.