-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make XMLBuilder generic * Reduce allocations at XmlData display impl * Implement streaming writers - Extend BuildXML trait, add the streaming method - Remove impls for Box<Ty>, as they can be implemented on the trait level - Rewrite build() methods in chaining style, backed by apply_* helpers - Remove quite a few allocations, though numbers still produce them - Add spaces between children nodes, fix tests * Add rustfmt.toml and format code * Fix clippy warnings * Expose the BuildXML trait without displaying its methods in hints
- Loading branch information
Showing
186 changed files
with
3,502 additions
and
4,407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,38 @@ | ||
use crate::xml_builder::XMLBuilder; | ||
use std::io::Write; | ||
|
||
pub trait BuildXML { | ||
fn build(&self) -> Vec<u8>; | ||
/// Write XML to the output stream. | ||
#[doc(hidden)] | ||
fn build_to<W: Write>( | ||
&self, | ||
stream: xml::writer::EventWriter<W>, | ||
) -> xml::writer::Result<xml::writer::EventWriter<W>>; | ||
|
||
#[doc(hidden)] | ||
fn build(&self) -> Vec<u8> { | ||
self.build_to(XMLBuilder::new(Vec::new()).into_inner().unwrap()) | ||
.expect("should write to buf") | ||
.into_inner() | ||
} | ||
} | ||
|
||
impl<'a, T: BuildXML> BuildXML for &'a T { | ||
/// Building XML from `&T` is the same as from `T`. | ||
fn build_to<W: Write>( | ||
&self, | ||
stream: xml::writer::EventWriter<W>, | ||
) -> xml::writer::Result<xml::writer::EventWriter<W>> { | ||
(*self).build_to(stream) | ||
} | ||
} | ||
|
||
impl<T: BuildXML> BuildXML for Box<T> { | ||
/// Building XML from `Box<T>` is the same as from `T`. | ||
fn build_to<W: Write>( | ||
&self, | ||
stream: xml::writer::EventWriter<W>, | ||
) -> xml::writer::Result<xml::writer::EventWriter<W>> { | ||
(**self).build_to(stream) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.