update format with version 0.4.1
This commit is contained in:
parent
c50b1aa4a8
commit
a951aa9ba0
@ -122,10 +122,7 @@ impl<'de, R: Read> Deserializer<R> {
|
||||
))
|
||||
}
|
||||
} else {
|
||||
Err(format!(
|
||||
"Unexpected token </{}>",
|
||||
start_name.local_name
|
||||
))
|
||||
Err(format!("Unexpected token </{}>", start_name.local_name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ pub trait Visitor<'de>: Sized {
|
||||
}
|
||||
|
||||
macro_rules! serialize_type {
|
||||
($type:ty) => (
|
||||
($type: ty) => {
|
||||
impl YaSerialize for $type {
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
|
||||
let content = format!("{}", self);
|
||||
@ -81,7 +81,7 @@ macro_rules! serialize_type {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
serialize_type!(bool);
|
||||
|
||||
@ -10,10 +10,10 @@ use yaserde::YaDeserialize;
|
||||
use yaserde::de::from_str;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($content:expr, $struct:tt, $model:expr) => {
|
||||
let loaded : Result<$struct, String> = from_str($content);
|
||||
($content: expr, $struct: tt, $model: expr) => {
|
||||
let loaded: Result<$struct, String> = from_str($content);
|
||||
assert_eq!(loaded, Ok($model));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -21,8 +21,10 @@ fn de_struct_namespace() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "book", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
||||
pub struct Book {
|
||||
#[yaserde(prefix = "ns")] author: String,
|
||||
#[yaserde(prefix = "ns")] title: String,
|
||||
#[yaserde(prefix = "ns")]
|
||||
author: String,
|
||||
#[yaserde(prefix = "ns")]
|
||||
title: String,
|
||||
}
|
||||
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ns:book xmlns:ns=\"http://www.sample.com/ns/domain\"><ns:author>Antoine de Saint-Exupéry</ns:author><ns:title>Little prince</ns:title></ns:book>";
|
||||
@ -45,7 +47,8 @@ fn de_enum_namespace() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
||||
pub enum XmlStruct {
|
||||
#[yaserde(prefix = "ns")] Item,
|
||||
#[yaserde(prefix = "ns")]
|
||||
Item,
|
||||
}
|
||||
|
||||
impl Default for XmlStruct {
|
||||
|
||||
@ -10,23 +10,21 @@ use yaserde::YaDeserialize;
|
||||
use yaserde::de::from_str;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($type:ty, $value:expr, $content:expr) => ({
|
||||
|
||||
($type: ty, $value: expr, $content: expr) => {{
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root="data")]
|
||||
#[yaserde(root = "data")]
|
||||
pub struct Data {
|
||||
item: $type
|
||||
item: $type,
|
||||
}
|
||||
|
||||
let model = Data {
|
||||
item: $value
|
||||
};
|
||||
let model = Data { item: $value };
|
||||
|
||||
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content + "</item></data>";
|
||||
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
|
||||
+ "</item></data>";
|
||||
|
||||
let loaded : Result<Data, String> = from_str(&content);
|
||||
let loaded: Result<Data, String> = from_str(&content);
|
||||
assert_eq!(loaded, Ok(model));
|
||||
})
|
||||
}};
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -10,10 +10,10 @@ use yaserde::YaDeserialize;
|
||||
use yaserde::de::from_str;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($content:expr, $struct:tt, $model:expr) => {
|
||||
let loaded : Result<$struct, String> = from_str($content);
|
||||
($content: expr, $struct: tt, $model: expr) => {
|
||||
let loaded: Result<$struct, String> = from_str($content);
|
||||
assert_eq!(loaded, Ok($model));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -93,14 +93,16 @@ fn de_attributes() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute)] item: String,
|
||||
#[yaserde(attribute)]
|
||||
item: String,
|
||||
sub: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute)] subitem: String,
|
||||
#[yaserde(attribute)]
|
||||
subitem: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -129,14 +131,17 @@ fn de_rename() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute, rename = "Item")] item: String,
|
||||
#[yaserde(rename = "sub")] sub_struct: SubStruct,
|
||||
#[yaserde(attribute, rename = "Item")]
|
||||
item: String,
|
||||
#[yaserde(rename = "sub")]
|
||||
sub_struct: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute, rename = "sub_item")] subitem: String,
|
||||
#[yaserde(attribute, rename = "sub_item")]
|
||||
subitem: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -165,15 +170,19 @@ fn de_text_content_with_attributes() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute, rename = "Item")] item: String,
|
||||
#[yaserde(rename = "sub")] sub_struct: SubStruct,
|
||||
#[yaserde(attribute, rename = "Item")]
|
||||
item: String,
|
||||
#[yaserde(rename = "sub")]
|
||||
sub_struct: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute, rename = "sub_item")] subitem: String,
|
||||
#[yaserde(text)] text: String,
|
||||
#[yaserde(attribute, rename = "sub_item")]
|
||||
subitem: String,
|
||||
#[yaserde(text)]
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -269,7 +278,8 @@ fn de_attribute_enum() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute)] background: Color,
|
||||
#[yaserde(attribute)]
|
||||
background: Color,
|
||||
}
|
||||
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
|
||||
@ -10,10 +10,10 @@ use yaserde::YaSerialize;
|
||||
use yaserde::ser::to_string;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($model:expr, $content:expr) => (
|
||||
let data : Result<String, String> = to_string(&$model);
|
||||
($model: expr, $content: expr) => {
|
||||
let data: Result<String, String> = to_string(&$model);
|
||||
assert_eq!(data, Ok(String::from($content)));
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -21,7 +21,8 @@ fn ser_struct_namespace() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(prefix = "ns")] item: String,
|
||||
#[yaserde(prefix = "ns")]
|
||||
item: String,
|
||||
}
|
||||
|
||||
let model = XmlStruct {
|
||||
@ -37,7 +38,8 @@ fn ser_enum_namespace() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
||||
pub enum XmlStruct {
|
||||
#[yaserde(prefix = "ns")] Item,
|
||||
#[yaserde(prefix = "ns")]
|
||||
Item,
|
||||
}
|
||||
|
||||
let model = XmlStruct::Item;
|
||||
@ -52,8 +54,10 @@ fn ser_struct_multi_namespace() {
|
||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(prefix = "ns1")] item_1: String,
|
||||
#[yaserde(prefix = "ns2")] item_2: String,
|
||||
#[yaserde(prefix = "ns1")]
|
||||
item_1: String,
|
||||
#[yaserde(prefix = "ns2")]
|
||||
item_2: String,
|
||||
}
|
||||
|
||||
let model = XmlStruct {
|
||||
@ -71,8 +75,10 @@ fn ser_enum_multi_namespace() {
|
||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
||||
pub enum XmlStruct {
|
||||
#[yaserde(prefix = "ns1")] Item1,
|
||||
#[yaserde(prefix = "ns2")] Item2,
|
||||
#[yaserde(prefix = "ns1")]
|
||||
Item1,
|
||||
#[yaserde(prefix = "ns2")]
|
||||
Item2,
|
||||
}
|
||||
|
||||
let model1 = XmlStruct::Item1;
|
||||
@ -89,8 +95,10 @@ fn ser_struct_attribute_namespace() {
|
||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(prefix = "ns1")] item_1: String,
|
||||
#[yaserde(attribute, prefix = "ns2")] item_2: String,
|
||||
#[yaserde(prefix = "ns1")]
|
||||
item_1: String,
|
||||
#[yaserde(attribute, prefix = "ns2")]
|
||||
item_2: String,
|
||||
}
|
||||
|
||||
let model = XmlStruct {
|
||||
|
||||
@ -10,21 +10,19 @@ use yaserde::YaSerialize;
|
||||
use yaserde::ser::to_string;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($type:ty, $value:expr, $content:expr) => ({
|
||||
|
||||
($type: ty, $value: expr, $content: expr) => {{
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root="data")]
|
||||
#[yaserde(root = "data")]
|
||||
pub struct Data {
|
||||
item: $type
|
||||
item: $type,
|
||||
}
|
||||
let model = Data {
|
||||
item: $value
|
||||
};
|
||||
let model = Data { item: $value };
|
||||
|
||||
let data : Result<String, String> = to_string(&model);
|
||||
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content + "</item></data>";
|
||||
let data: Result<String, String> = to_string(&model);
|
||||
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
|
||||
+ "</item></data>";
|
||||
assert_eq!(data, Ok(content));
|
||||
})
|
||||
}};
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -10,10 +10,10 @@ use yaserde::YaSerialize;
|
||||
use yaserde::ser::to_string;
|
||||
|
||||
macro_rules! convert_and_validate {
|
||||
($model:expr, $content:expr) => (
|
||||
let data : Result<String, String> = to_string(&$model);
|
||||
($model: expr, $content: expr) => {
|
||||
let data: Result<String, String> = to_string(&$model);
|
||||
assert_eq!(data, Ok(String::from($content)));
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -79,14 +79,16 @@ fn se_attributes() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute)] item: String,
|
||||
#[yaserde(attribute)]
|
||||
item: String,
|
||||
sub: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute)] subitem: String,
|
||||
#[yaserde(attribute)]
|
||||
subitem: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -113,14 +115,17 @@ fn ser_rename() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute, rename = "Item")] item: String,
|
||||
#[yaserde(rename = "sub")] sub_struct: SubStruct,
|
||||
#[yaserde(attribute, rename = "Item")]
|
||||
item: String,
|
||||
#[yaserde(rename = "sub")]
|
||||
sub_struct: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute, rename = "sub_item")] subitem: String,
|
||||
#[yaserde(attribute, rename = "sub_item")]
|
||||
subitem: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -147,15 +152,19 @@ fn ser_text_content_with_attributes() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute, rename = "Item")] item: String,
|
||||
#[yaserde(rename = "sub")] sub_struct: SubStruct,
|
||||
#[yaserde(attribute, rename = "Item")]
|
||||
item: String,
|
||||
#[yaserde(rename = "sub")]
|
||||
sub_struct: SubStruct,
|
||||
}
|
||||
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "sub")]
|
||||
pub struct SubStruct {
|
||||
#[yaserde(attribute, rename = "sub_item")] subitem: String,
|
||||
#[yaserde(text)] text: String,
|
||||
#[yaserde(attribute, rename = "sub_item")]
|
||||
subitem: String,
|
||||
#[yaserde(text)]
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl Default for SubStruct {
|
||||
@ -249,13 +258,15 @@ fn ser_attribute_enum() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
#[yaserde(attribute)] color: Color,
|
||||
#[yaserde(attribute)]
|
||||
color: Color,
|
||||
}
|
||||
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "color")]
|
||||
pub enum Color {
|
||||
#[yaserde(rename = "pink")] Pink,
|
||||
#[yaserde(rename = "pink")]
|
||||
Pink,
|
||||
}
|
||||
|
||||
let model = XmlStruct { color: Color::Pink };
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
extern crate proc_macro2;
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
extern crate syn;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user