diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-04-10 08:04:05 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-04-10 08:04:05 +0300 |
commit | 33b057ffb1d74c7ac10961f49c43e777e581a7e7 (patch) | |
tree | d2c3e0331d9c01b70fea656ec2c812c1617bc8b7 | |
parent | 9e3623a0fae24019abfcd8858aa87030e76e08ac (diff) | |
download | html-page-33b057ffb1d74c7ac10961f49c43e777e581a7e7.tar.gz |
feat: return attribute value as a string
Sponsored-by: author
-rw-r--r-- | src/lib.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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] |