Replace xml-rs by quick_xml

quick_xml is way faster than xml-rs

Here is an example with a quick atom parser:
    With xml-rs:
        test parse_factorio_atom ... bench:   3,295,678 ns/iter (+/- 165,851)
    With quick_xml:
        test parse_factorio_atom ... bench:     203,215 ns/iter (+/- 13,485)

Unfortunately I had to break the API for this change to happen.
* Element::from_reader now takes `R: BufRead` instead of `R: Read`
* Element::write_to now takes `W: io::Write` instead of `EventWriter<W: Write>`

This migration also allow us to have a write_to function which assumes
we're already in a given namespace (see `write_to_in_namespace`).
This commit is contained in:
Bastien Orivel 2017-06-07 22:40:53 +02:00
commit 9cec9fce9b
5 changed files with 153 additions and 124 deletions

View file

@ -1,30 +1,30 @@
//! Provides an error type for this crate.
use std::io;
use std::convert::From;
use xml::writer::Error as WriterError;
use xml::reader::Error as ReaderError;
error_chain! {
foreign_links {
XmlWriterError(WriterError)
/// An error with writing an XML event, from xml::writer::EventWriter.
XmlError(::quick_xml::errors::Error)
/// An error from quick_xml.
;
XmlReaderError(ReaderError)
/// An error with reading an XML event, from xml::reader::EventReader.
Utf8Error(::std::str::Utf8Error)
/// An UTF-8 conversion error.
;
IoError(io::Error)
IoError(::std::io::Error)
/// An I/O error, from std::io.
;
}
errors {
/// En error which is returned when the end of the document was reached prematurely.
/// An error which is returned when the end of the document was reached prematurely.
EndOfDocument {
description("the end of the document has been reached prematurely")
display("the end of the document has been reached prematurely")
}
/// An error which is returned when an element is closed when it shouldn't be
InvalidElementClosed {
description("The XML is invalid, an element was wrongly closed")
display("the XML is invalid, an element was wrongly closed")
}
}
}