format code
This commit is contained in:
@@ -12,7 +12,10 @@ pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
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 cursor = serialize_with_writer(model, buf)?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
@@ -104,5 +107,5 @@ impl<'de, W: Write> Serializer<W> {
|
||||
pub struct Config {
|
||||
perform_indent: bool,
|
||||
write_document_declaration: bool,
|
||||
indent_string: Option<String>
|
||||
indent_string: Option<String>,
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ fn de_struct_namespace() {
|
||||
root = "book",
|
||||
prefix = "ns",
|
||||
namespace = "ns: http://www.sample.com/ns/domain",
|
||||
namespace = "ns2: http://www.sample.com/ns/domain_2",
|
||||
namespace = "ns2: http://www.sample.com/ns/domain_2"
|
||||
)]
|
||||
pub struct Book {
|
||||
#[yaserde(prefix = "ns")]
|
||||
@@ -83,7 +83,10 @@ fn de_struct_namespace() {
|
||||
<ns:title>Little prince</ns:title>
|
||||
</ns:book>"#;
|
||||
let loaded: Result<Book, String> = from_str(content);
|
||||
assert_eq!(loaded, Err("bad namespace for book, found http://www.sample.com/ns/domain2".to_string()));
|
||||
assert_eq!(
|
||||
loaded,
|
||||
Err("bad namespace for book, found http://www.sample.com/ns/domain2".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -36,7 +36,8 @@ fn se_default_field_string() {
|
||||
},
|
||||
content
|
||||
);
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>my_value</background></base>";
|
||||
let content =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>my_value</background></base>";
|
||||
convert_and_validate!(
|
||||
XmlStruct {
|
||||
background: "my_value".to_string(),
|
||||
@@ -61,13 +62,9 @@ fn se_default_field_boolean() {
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base />";
|
||||
convert_and_validate!(XmlStruct { background: true }, content);
|
||||
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>false</background></base>";
|
||||
convert_and_validate!(
|
||||
XmlStruct {
|
||||
background: false,
|
||||
},
|
||||
content
|
||||
);
|
||||
let content =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?><base><background>false</background></base>";
|
||||
convert_and_validate!(XmlStruct { background: false }, content);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user