diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/token.rs | 16 | ||||
-rw-r--r-- | src/tracing_emitter.rs | 5 |
3 files changed, 20 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f175d7..f48b124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,10 @@ * Removed `CdataAction` and changed `handle_cdata_open` to just take a boolean instead. +* `AttributeMap::get` now just returns `Option<&str>` as you would expect. + To obtain the value and attribute trace, you now have to use the + newly added `AttributeMap::value_and_trace_idx` method. + * Three variants of the `State` enum have been renamed according to the Rust API guidelines (`RcData` to `Rcdata`, `RawText` to `Rawtext` and `PlainText` to `Plaintext`). 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)) } } diff --git a/src/tracing_emitter.rs b/src/tracing_emitter.rs index 21f40f7..9591839 100644 --- a/src/tracing_emitter.rs +++ b/src/tracing_emitter.rs @@ -365,7 +365,10 @@ mod tests { ("single-quoted", Some(AttrValueSyntax::SingleQuoted)), ("double-quoted", Some(AttrValueSyntax::DoubleQuoted)), ] { - let attr_trace_idx = tag.attributes.get(name).unwrap().trace_idx().unwrap(); + let (_, Some(attr_trace_idx)) = tag.attributes.value_and_trace_idx(name).unwrap() + else { + panic!() + }; assert_eq!( tag_trace.attribute_traces[attr_trace_idx].value_syntax(), syntax, |