XML prettyprint documentation
This commit is contained in:
parent
e84d92a864
commit
9bbb1a6cc9
@ -8,6 +8,6 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
yaserde = {version = "0.6", path = "../yaserde" }
|
yaserde = {version = "0.6", path = "../yaserde" }
|
||||||
yaserde_derive = {version = "0.6", path = "../yaserde_derive" }
|
yaserde_derive = {version = "0.6", path = "../yaserde_derive" }
|
||||||
xml-rs = "0.8.0"
|
xml-rs = "0.8.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
simple_logger = "1.0"
|
simple_logger = "1.11.0"
|
||||||
|
|||||||
@ -58,10 +58,9 @@
|
|||||||
//! example).
|
//! example).
|
||||||
//!
|
//!
|
||||||
//! Be mindful that the **Cargo.toml** should not only include `yaserde` and
|
//! Be mindful that the **Cargo.toml** should not only include `yaserde` and
|
||||||
//! `yaserde_derive`, but also a few necessary dependencies... [FIXME: THAT FOR SOME
|
//! `yaserde_derive`, but also `xml-rs` and `log` as your dependencies...
|
||||||
//! 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
|
//! [FIXME: Explain better why YaSerDe does not pull `xml-rs` and `log` automatically?](https://github.com/media-io/yaserde/issues/22)
|
||||||
//! 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).**
|
|
||||||
//!
|
//!
|
||||||
//!```toml
|
//!```toml
|
||||||
//! [dependencies]
|
//! [dependencies]
|
||||||
@ -73,13 +72,20 @@
|
|||||||
//! log = "0.4"
|
//! 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
|
//! ```ignore
|
||||||
//! PLEASE LET THE USERS KNOW HOW TO DO THAT CLEARLY ON YASERDE???
|
//! // 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]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use std::str;
|
|||||||
use xml::writer::XmlEvent;
|
use xml::writer::XmlEvent;
|
||||||
use xml::{EmitterConfig, EventWriter};
|
use xml::{EmitterConfig, EventWriter};
|
||||||
|
|
||||||
|
/// Serialize XML into a plain String with no formatting (EmitterConfig).
|
||||||
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||||
let buf = Cursor::new(Vec::new());
|
let buf = Cursor::new(Vec::new());
|
||||||
let cursor = serialize_with_writer(model, buf, &Config::default())?;
|
let cursor = serialize_with_writer(model, buf, &Config::default())?;
|
||||||
@ -14,6 +15,7 @@ pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
|||||||
Ok(data.into())
|
Ok(data.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize XML into a plain String with control on formatting (via EmitterConfig parameters)
|
||||||
pub fn to_string_with_config<T: YaSerialize>(model: &T, config: &Config) -> Result<String, String> {
|
pub fn to_string_with_config<T: YaSerialize>(model: &T, config: &Config) -> Result<String, String> {
|
||||||
let buf = Cursor::new(Vec::new());
|
let buf = Cursor::new(Vec::new());
|
||||||
let cursor = serialize_with_writer(model, buf, config)?;
|
let cursor = serialize_with_writer(model, buf, config)?;
|
||||||
|
|||||||
@ -16,6 +16,8 @@ heck = "0.3.1"
|
|||||||
syn = { version = "~1.0", features = ["visit", "extra-traits"] }
|
syn = { version = "~1.0", features = ["visit", "extra-traits"] }
|
||||||
proc-macro2 = "~1.0"
|
proc-macro2 = "~1.0"
|
||||||
quote = "~1.0"
|
quote = "~1.0"
|
||||||
|
xml-rs = "0.8.3"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user