aboutsummaryrefslogtreecommitdiff
path: root/src/token.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/token.rs')
-rw-r--r--src/token.rs35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/token.rs b/src/token.rs
index da1f8ba..2afef8c 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -1,6 +1,7 @@
//! Provides the [`Token`] type.
use std::collections::{btree_map, BTreeMap};
+use std::fmt::Debug;
use std::iter::FromIterator;
use std::ops::Index;
@@ -86,14 +87,14 @@ pub struct Doctype {
/// .collect();
/// assert_eq!(&attrs["href"], "http://example.com");
/// ```
-#[derive(Clone, Debug, Default, PartialEq, Eq)]
+#[derive(Clone, Default, PartialEq, Eq)] // Debug has a custom impl below
pub struct AttributeMap {
pub(crate) inner: BTreeMap<String, AttrInternal>,
}
/// The value type internally used by the [`AttributeMap`].
/// Not part of the public API.
-#[derive(Clone, Default, Debug, Eq)]
+#[derive(Clone, Default, Eq)] // Debug has a custom impl below
pub(crate) struct AttrInternal {
pub value: String,
pub trace_idx: Option<AttributeTraceIdx>,
@@ -119,7 +120,7 @@ impl PartialEq for AttrInternal {
}
/// An HTML attribute borrowed from an [`AttributeMap`].
-#[derive(Debug, Eq, PartialEq)]
+#[derive(Eq, PartialEq)] // Debug has a custom impl below
pub struct Attribute<'a> {
name: &'a str,
map_val: &'a AttrInternal,
@@ -267,3 +268,31 @@ impl FromIterator<(String, String)> for AttributeMap {
}
}
}
+
+impl Debug for AttributeMap {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ self.inner.fmt(f)
+ }
+}
+
+impl Debug for AttrInternal {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "{:?}", self.value)?;
+
+ if let Some(idx) = self.trace_idx {
+ write!(f, " (trace #{})", idx.0)?;
+ }
+
+ Ok(())
+ }
+}
+
+impl Debug for Attribute<'_> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("Attribute")
+ .field("name", &self.name)
+ .field("value", &self.value())
+ .field("trace_idx", &self.trace_idx().map(|idx| idx.0))
+ .finish()
+ }
+}