Closed untitaker closed 8 years ago
I’ve added some convenience methods in 29d69a2a995ba58c5efcc689a93846e780524eba and publish it as 0.2.
https://simonsapin.github.io/kuchiki/kuchiki/struct.Attributes.html
for element in doc.select("something") {
let attributes = element.attributes.borrow();
if let Some(icon) = attributes.get(atom!("icon")) {
// ...
}
}
Use #[macro_use] extern crate string_cache;
to get the atom!
macro. It "interns" a string a compile-time, but only for strings listed at: https://simonsapin.github.io/kuchiki/string_cache/macro.atom!.html
The methods also accept &str
, but in that case they do the string interning themselves at a small run-time cost.
Let me know how it goes in practice or if other convenience things can be added.
This is slightly better, thank you. Apart from this one I couldn't find any ergonomics-issues.
Since kuchiki 0.4 this no longer appears to work. I suppose I have to use html5ever-atoms
, but their qualname macro requires an additional namespace parameter (not appropriate for html).
EDIT: Apparently local_name!
does the trick.
the
attributes
field onElementData
is aHashMap<QualName, String>
.QualName
doesn't implEq
for anything but itself, accessing a specific attribute requires constructing aQualName
object.