-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow srializer with custom eventwriter
This way, one can configure parametes for the xml crate, like indentation
- Loading branch information
1 parent
920e54d
commit 44bca2d
Showing
2 changed files
with
28 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use serde::{Serialize}; | ||
use xml::EmitterConfig; | ||
use serde_xml_rs::Serializer; | ||
|
||
#[derive(Debug, Serialize, PartialEq)] | ||
struct Item { | ||
name: String, | ||
source: String, | ||
} | ||
|
||
#[test] | ||
fn serializer_should_accept_custom_emitter() { | ||
let item = Item { | ||
name: "john".to_string(), | ||
source: "outerworld".to_string(), | ||
}; | ||
let mut output = Vec::new(); | ||
{ | ||
let w = EmitterConfig::default().perform_indent(true).create_writer(&mut output); | ||
let mut serializer = Serializer::with_writer(w); | ||
item.serialize(&mut serializer).unwrap(); | ||
} | ||
assert_eq!("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Item>\n <name>john</name>\n <source>outerworld</source>\n</Item>", String::from_utf8_lossy(&output)); | ||
} |