aboutsummaryrefslogtreecommitdiff
path: root/src/token.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2023-09-27 08:05:58 +0200
committerMartin Fischer <martin@push-f.com>2023-09-28 10:36:08 +0200
commit3c89744824ea6b8b32d82c2c37ac1de6d980709c (patch)
treef09c32d629507af4ae99b05bd9629cffeba879bc /src/token.rs
parentc75dce875cff03e59ec7b6bceed4ec63283a6477 (diff)
break!: make AttributeMap::get return Option<&str>
Most of the time you'll only be interested in the attribute value, so the `get` method should directly return it instead of a wrapper type. This also makes the API more predictable since e.g. the DOM getAttribute method also returns a string. Lastly previously it was quite confusing that map[key] wasn't equivalent to map.get(key).unwrap().
Diffstat (limited to 'src/token.rs')
-rw-r--r--src/token.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/token.rs b/src/token.rs
index 45c8123..da1f8ba 100644
--- a/src/token.rs
+++ b/src/token.rs
@@ -144,14 +144,22 @@ pub struct AttributeOwned {
}
impl AttributeMap {
- /// Returns the attribute with the given name.
+ /// Returns the value for the given attribute name.
///
/// The name must not contain any uppercase ASCII character (A-Z)
/// or the method will always return `None`.
- pub fn get(&self, name: &str) -> Option<Attribute> {
+ pub fn get(&self, name: &str) -> Option<&str> {
+ self.inner.get(name).map(|map_val| map_val.value.as_str())
+ }
+
+ /// Returns the value and trace index for a given attribute name.
+ ///
+ /// The name must not contain any uppercase ASCII character (A-Z)
+ /// or the method will always return `None`.
+ pub fn value_and_trace_idx(&self, name: &str) -> Option<(&str, Option<AttributeTraceIdx>)> {
self.inner
- .get_key_value(name)
- .map(|(name, map_val)| Attribute { name, map_val })
+ .get(name)
+ .map(|map_val| (map_val.value.as_str(), map_val.trace_idx))
}
}