Skip to content

Commit 40538b7

Browse files
weiznichMingun
authored andcommitted
Improve debug representation of Attribute and Attributes
1 parent c8fe850 commit 40538b7

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/events/attributes.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::encoding::Decoder;
66
use crate::errors::Result as XmlResult;
77
use crate::escape::{escape, resolve_predefined_entity, unescape_with};
88
use crate::name::QName;
9-
use crate::utils::{is_whitespace, write_byte_string, write_cow_string, Bytes};
9+
use crate::utils::{is_whitespace, Bytes};
1010

1111
use std::fmt::{self, Debug, Display, Formatter};
1212
use std::iter::FusedIterator;
@@ -100,11 +100,10 @@ impl<'a> Attribute<'a> {
100100

101101
impl<'a> Debug for Attribute<'a> {
102102
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
103-
write!(f, "Attribute {{ key: ")?;
104-
write_byte_string(f, self.key.as_ref())?;
105-
write!(f, ", value: ")?;
106-
write_cow_string(f, &self.value)?;
107-
write!(f, " }}")
103+
f.debug_struct("Attribute")
104+
.field("key", &Bytes(self.key.as_ref()))
105+
.field("value", &Bytes(&self.value))
106+
.finish()
108107
}
109108
}
110109

@@ -196,7 +195,7 @@ impl<'a> From<Attr<&'a [u8]>> for Attribute<'a> {
196195
/// The duplicate check can be turned off by calling [`with_checks(false)`].
197196
///
198197
/// [`with_checks(false)`]: Self::with_checks
199-
#[derive(Clone, Debug)]
198+
#[derive(Clone)]
200199
pub struct Attributes<'a> {
201200
/// Slice of `BytesStart` corresponding to attributes
202201
bytes: &'a [u8],
@@ -236,6 +235,15 @@ impl<'a> Attributes<'a> {
236235
}
237236
}
238237

238+
impl<'a> Debug for Attributes<'a> {
239+
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
240+
f.debug_struct("Attributes")
241+
.field("bytes", &Bytes(&self.bytes))
242+
.field("state", &self.state)
243+
.finish()
244+
}
245+
}
246+
239247
impl<'a> Iterator for Attributes<'a> {
240248
type Item = Result<Attribute<'a>, AttrError>;
241249

0 commit comments

Comments
 (0)