Use a BTreeMap<String, String> instead of a Vec<Attribute> to store attributes

This way we don't need to reimplement PartialEq for Element. It's also
way easier to get an attribute by name as we don't need to iterate over
every attribute to see if it exists.

The only side effect is that now, in the Debug output, attributes are
automatically sorted by names instead of being sorted by insertion
order.

Fixes #4
This commit is contained in:
Bastien Orivel 2017-04-26 23:44:58 +02:00
commit f87e2442d4
4 changed files with 29 additions and 95 deletions

View file

@ -7,7 +7,7 @@ use xml::writer::EventWriter;
use element::Element;
const TEST_STRING: &'static str = r#"<?xml version="1.0" encoding="utf-8"?><root xmlns="root_ns" xml:lang="en" a="b">meow<child c="d" /><child xmlns="child_ns" d="e" xml:lang="fr" />nya</root>"#;
const TEST_STRING: &'static str = r#"<?xml version="1.0" encoding="utf-8"?><root xmlns="root_ns" a="b" xml:lang="en">meow<child c="d" /><child xmlns="child_ns" d="e" xml:lang="fr" />nya</root>"#;
fn build_test_tree() -> Element {
let mut root = Element::builder("root")