summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-04-10 08:04:05 +0300
committerLars Wirzenius <liw@liw.fi>2023-04-10 08:04:05 +0300
commit33b057ffb1d74c7ac10961f49c43e777e581a7e7 (patch)
treed2c3e0331d9c01b70fea656ec2c812c1617bc8b7
parent9e3623a0fae24019abfcd8858aa87030e76e08ac (diff)
downloadhtml-page-33b057ffb1d74c7ac10961f49c43e777e581a7e7.tar.gz
feat: return attribute value as a string
Sponsored-by: author
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 374518d..50ec205 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -385,6 +385,17 @@ pub enum AttributeValue {
Boolean,
}
+impl AttributeValue {
+ /// Return value of an attribute as a string. For a boolean
+ /// attribute, this is the empty string.
+ pub fn as_str(&self) -> &str {
+ match self {
+ Self::String(s) => s,
+ Self::Boolean => "",
+ }
+ }
+}
+
/// An HTML element.
///
/// The element has a [`Tag`], possibly some attributes, and possibly
@@ -665,6 +676,7 @@ mod test {
e.attribute("foo"),
Some(&AttributeValue::String("bar".into()))
);
+ assert_eq!(e.attribute("foo").map(|x| x.as_str()), Some("bar"));
}
#[test]