diff --git a/minidom-rs/CHANGELOG.md b/minidom-rs/CHANGELOG.md index b1dec9c343d642f2c313af34cd2a953a1862f22e..9cef50c4dc2621f427d6b02f8014c2740f5bff21 100644 --- a/minidom-rs/CHANGELOG.md +++ b/minidom-rs/CHANGELOG.md @@ -1,4 +1,6 @@ Version XXX, released YYY: + * Breaking + `Element.write_to` doesn't prepand xml prelude anymore. Use `write_to_decl`. * Changes * Update edition to 2018 * Add NSChoice enum to allow comparing NSs differently diff --git a/minidom-rs/src/element.rs b/minidom-rs/src/element.rs index f2d814a296c0e2087b2038300af5e616963b254f..a9da2531a8970489056c2fc945624ebbdeea03e3 100644 --- a/minidom-rs/src/element.rs +++ b/minidom-rs/src/element.rs @@ -414,8 +414,18 @@ impl Element { self.to_writer(&mut EventWriter::new(writer)) } + /// Output a document to a `Writer`. + pub fn write_to_decl(&self, writer: &mut W) -> Result<()> { + self.to_writer_decl(&mut EventWriter::new(writer)) + } + /// Output the document to quick-xml `Writer` pub fn to_writer(&self, writer: &mut EventWriter) -> Result<()> { + self.write_to_inner(writer) + } + + /// Output the document to quick-xml `Writer` + pub fn to_writer_decl(&self, writer: &mut EventWriter) -> Result<()> { writer.write_event(Event::Decl(BytesDecl::new(b"1.0", Some(b"utf-8"), None)))?; self.write_to_inner(writer) } diff --git a/minidom-rs/src/tests.rs b/minidom-rs/src/tests.rs index 22e257aa04dd6a17192d795e05b72cdb78e4406d..8798833dba6d0060a135ba687eb6bbc23e624ddf 100644 --- a/minidom-rs/src/tests.rs +++ b/minidom-rs/src/tests.rs @@ -2,7 +2,7 @@ use crate::element::Element; use quick_xml::Reader; -const TEST_STRING: &'static str = r#"meownya"#; +const TEST_STRING: &'static str = r#"meownya"#; fn build_test_tree() -> Element { let mut root = Element::builder("root") @@ -24,7 +24,7 @@ fn build_test_tree() -> Element { } #[cfg(feature = "comments")] -const COMMENT_TEST_STRING: &'static str = r#""#; +const COMMENT_TEST_STRING: &'static str = r#""#; #[cfg(feature = "comments")] fn build_comment_test_tree() -> Element { @@ -57,6 +57,17 @@ fn writer_works() { assert_eq!(String::from_utf8(writer).unwrap(), TEST_STRING); } +#[test] +fn writer_with_decl_works() { + let root = build_test_tree(); + let mut writer = Vec::new(); + { + root.write_to_decl(&mut writer).unwrap(); + } + let result = format!(r#"{}"#, TEST_STRING); + assert_eq!(String::from_utf8(writer).unwrap(), result); +} + #[test] fn writer_escapes_attributes() { let root = Element::builder("root").attr("a", "\"Air\" quotes").build(); @@ -66,7 +77,7 @@ fn writer_escapes_attributes() { } assert_eq!( String::from_utf8(writer).unwrap(), - r#""# + r#""# ); } @@ -77,10 +88,7 @@ fn writer_escapes_text() { { root.write_to(&mut writer).unwrap(); } - assert_eq!( - String::from_utf8(writer).unwrap(), - r#"<3"# - ); + assert_eq!(String::from_utf8(writer).unwrap(), r#"<3"#); } #[test] diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index f0a88e9c257bcbf824e168de2176b58c97d0bb54..3e6e93628904c22b3eebf6af2739dbcdeed2ffce 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -23,6 +23,5 @@ trust-dns-resolver = "0.12" trust-dns-proto = "0.8" tokio-io = "0.1" tokio-tls = "0.2" -quick-xml = "0.17" xml5ever = "0.15" xmpp-parsers = "0.16" diff --git a/tokio-xmpp/src/xmpp_codec.rs b/tokio-xmpp/src/xmpp_codec.rs index 39234069aef106614ab3e5de9daba32e736a1063..236ff75a5d469f172cc76272e87f6358b58b1888 100644 --- a/tokio-xmpp/src/xmpp_codec.rs +++ b/tokio-xmpp/src/xmpp_codec.rs @@ -2,7 +2,6 @@ use crate::{ParseError, ParserError}; use bytes::{BufMut, BytesMut}; -use quick_xml::Writer as EventWriter; use std; use std::borrow::Cow; use std::cell::RefCell; @@ -302,7 +301,7 @@ impl Encoder for XMPPCodec { } Packet::Stanza(stanza) => { stanza - .write_to_inner(&mut EventWriter::new(WriteBytes::new(dst))) + .write_to(&mut WriteBytes::new(dst)) .and_then(|_| { // println!(">> {:?}", dst); Ok(()) diff --git a/xmpp-parsers/src/xhtml.rs b/xmpp-parsers/src/xhtml.rs index 6049a5fb4e57d517fc4e6a5912508ed99b08b78e..6eacbc947a3cb3226b34f78f1a8b4f6bbb70dc8f 100644 --- a/xmpp-parsers/src/xhtml.rs +++ b/xmpp-parsers/src/xhtml.rs @@ -607,7 +607,7 @@ mod tests { assert_eq!(html, "Hello world!"); let elem = Element::from(parsed2); - assert_eq!(String::from(&elem), "Hello world!"); + assert_eq!(String::from(&elem), "Hello world!"); } #[test]