diff --git a/examples/Cargo.toml b/examples/Cargo.toml index b841e6c..648a687 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -8,6 +8,6 @@ edition = "2018" [dependencies] yaserde = {version = "0.6", path = "../yaserde" } yaserde_derive = {version = "0.6", path = "../yaserde_derive" } -xml-rs = "0.8.0" +xml-rs = "0.8.3" log = "0.4" -simple_logger = "1.0" +simple_logger = "1.11.0" diff --git a/yaserde/src/lib.rs b/yaserde/src/lib.rs index 9aaafce..b4a1a3c 100644 --- a/yaserde/src/lib.rs +++ b/yaserde/src/lib.rs @@ -58,10 +58,9 @@ //! example). //! //! Be mindful that the **Cargo.toml** should not only include `yaserde` and -//! `yaserde_derive`, but also a few necessary dependencies... [FIXME: THAT FOR SOME -//! USER-UNFRIENDLY REASON ARE NOT AUTOMATICALLY PULLED IN AS ONE WOULD EXPECT ;P ;P -//! ... I'm sure there are good reasons, just wanted to leave this like this so that the author -//! can chip in and comment about the reasons behind that decision.](https://github.com/media-io/yaserde/issues/22) ... **I personally think that issue #22 should be reopened and fixed properly (as in only requiring yaserde as a dependency, adding yaserde_derive as a feature).** +//! `yaserde_derive`, but also `xml-rs` and `log` as your dependencies... +//! +//! [FIXME: Explain better why YaSerDe does not pull `xml-rs` and `log` automatically?](https://github.com/media-io/yaserde/issues/22) //! //!```toml //! [dependencies] @@ -73,13 +72,20 @@ //! log = "0.4" //! ``` //! -//! Last but not least, in order to have a nice, pretty printed XML output one can do +//! Last but not least, in order to have a nice, pretty printed XML output one can do: //! -//! ```shell -//! PLEASE LET THE USERS KNOW HOW TO DO THAT CLEARLY ON YASERDE??? +//! ```ignore +//! // Display pretty printed XML +//! let yaserde_cfg = yaserde::ser::Config{ +//! perform_indent: true, +//! .. Default::default() +//! }; +//! +//! println!("{}", yaserde::ser::to_string_with_config(&dev, &yaserde_cfg).ok().unwrap()); //! ``` //! -//! FIXME: For now I'm just resorting to online XML linters and formatters :_S +//! Avoid using either `{:?}` or `{:#?}` println! formatters since it'll garble the output of your +//! XML. #[macro_use] extern crate log; diff --git a/yaserde/src/ser/mod.rs b/yaserde/src/ser/mod.rs index 4b35213..1697a41 100644 --- a/yaserde/src/ser/mod.rs +++ b/yaserde/src/ser/mod.rs @@ -7,6 +7,7 @@ use std::str; use xml::writer::XmlEvent; use xml::{EmitterConfig, EventWriter}; +/// Serialize XML into a plain String with no formatting (EmitterConfig). pub fn to_string(model: &T) -> Result { let buf = Cursor::new(Vec::new()); let cursor = serialize_with_writer(model, buf, &Config::default())?; @@ -14,6 +15,7 @@ pub fn to_string(model: &T) -> Result { Ok(data.into()) } +/// Serialize XML into a plain String with control on formatting (via EmitterConfig parameters) pub fn to_string_with_config(model: &T, config: &Config) -> Result { let buf = Cursor::new(Vec::new()); let cursor = serialize_with_writer(model, buf, config)?; diff --git a/yaserde_derive/Cargo.toml b/yaserde_derive/Cargo.toml index ce5dc7f..e6524a1 100644 --- a/yaserde_derive/Cargo.toml +++ b/yaserde_derive/Cargo.toml @@ -16,6 +16,8 @@ heck = "0.3.1" syn = { version = "~1.0", features = ["visit", "extra-traits"] } proc-macro2 = "~1.0" quote = "~1.0" +xml-rs = "0.8.3" +log = "0.4" [lib] proc-macro = true