format code
This commit is contained in:
parent
96bac71db5
commit
69a54eebcf
@ -1,9 +1,10 @@
|
|||||||
language: rust
|
language: rust
|
||||||
rust:
|
rust:
|
||||||
- 1.23.0
|
|
||||||
- 1.24.0
|
|
||||||
- 1.25.0
|
|
||||||
- 1.26.0
|
- 1.26.0
|
||||||
|
- 1.27.0
|
||||||
|
- 1.28.0
|
||||||
|
- 1.29.0
|
||||||
|
- 1.30.0
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use xml::reader::{EventReader, ParserConfig, XmlEvent};
|
|
||||||
use xml::name::OwnedName;
|
use xml::name::OwnedName;
|
||||||
|
use xml::reader::{EventReader, ParserConfig, XmlEvent};
|
||||||
use YaDeserialize;
|
use YaDeserialize;
|
||||||
|
|
||||||
pub fn from_str<T: YaDeserialize>(s: &str) -> Result<T, String> {
|
pub fn from_str<T: YaDeserialize>(s: &str) -> Result<T, String> {
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
use std::str;
|
|
||||||
use std::io::{Cursor, Write};
|
use std::io::{Cursor, Write};
|
||||||
use xml::{EmitterConfig, EventWriter};
|
use std::str;
|
||||||
use xml;
|
use xml;
|
||||||
use xml::writer::XmlEvent;
|
use xml::writer::XmlEvent;
|
||||||
|
use xml::{EmitterConfig, EventWriter};
|
||||||
use YaSerialize;
|
use YaSerialize;
|
||||||
|
|
||||||
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use yaserde::YaDeserialize;
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
use yaserde::YaDeserialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($content: expr, $struct: tt, $model: expr) => {
|
($content: expr, $struct: tt, $model: expr) => {
|
||||||
@ -19,7 +19,11 @@ macro_rules! convert_and_validate {
|
|||||||
#[test]
|
#[test]
|
||||||
fn de_struct_namespace() {
|
fn de_struct_namespace() {
|
||||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "book", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
#[yaserde(
|
||||||
|
root = "book",
|
||||||
|
prefix = "ns",
|
||||||
|
namespace = "ns: http://www.sample.com/ns/domain"
|
||||||
|
)]
|
||||||
pub struct Book {
|
pub struct Book {
|
||||||
#[yaserde(prefix = "ns")]
|
#[yaserde(prefix = "ns")]
|
||||||
author: String,
|
author: String,
|
||||||
@ -45,7 +49,11 @@ fn de_struct_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn de_enum_namespace() {
|
fn de_enum_namespace() {
|
||||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
#[yaserde(
|
||||||
|
root = "root",
|
||||||
|
prefix = "ns",
|
||||||
|
namespace = "ns: http://www.sample.com/ns/domain"
|
||||||
|
)]
|
||||||
pub enum XmlStruct {
|
pub enum XmlStruct {
|
||||||
#[yaserde(prefix = "ns")]
|
#[yaserde(prefix = "ns")]
|
||||||
Item,
|
Item,
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use yaserde::YaDeserialize;
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
use yaserde::YaDeserialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($type: ty, $value: expr, $content: expr) => {{
|
($type: ty, $value: expr, $content: expr) => {{
|
||||||
@ -20,7 +20,8 @@ macro_rules! convert_and_validate {
|
|||||||
let model = Data { item: $value };
|
let model = Data { item: $value };
|
||||||
|
|
||||||
let source = if let Some(content) = $content {
|
let source = if let Some(content) = $content {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + content
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
|
||||||
|
+ content
|
||||||
+ "</item></data>"
|
+ "</item></data>"
|
||||||
} else {
|
} else {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
||||||
@ -43,7 +44,8 @@ macro_rules! convert_and_validate_for_attribute {
|
|||||||
let model = Data { item: $value };
|
let model = Data { item: $value };
|
||||||
|
|
||||||
let source = if let Some(content) = $content {
|
let source = if let Some(content) = $content {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data item=\"") + content
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data item=\"")
|
||||||
|
+ content
|
||||||
+ "\"></data>"
|
+ "\"></data>"
|
||||||
} else {
|
} else {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use yaserde::YaDeserialize;
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
use yaserde::YaDeserialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($type:ty, $value:expr, $content:expr) => {{
|
($type:ty, $value:expr, $content:expr) => {{
|
||||||
@ -19,7 +19,8 @@ macro_rules! convert_and_validate {
|
|||||||
|
|
||||||
let model = Data { item: $value };
|
let model = Data { item: $value };
|
||||||
|
|
||||||
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
|
let content = String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
|
||||||
|
+ $content
|
||||||
+ "</item></data>";
|
+ "</item></data>";
|
||||||
|
|
||||||
let loaded: Result<Data, String> = from_str(&content);
|
let loaded: Result<Data, String> = from_str(&content);
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use yaserde::YaDeserialize;
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
use yaserde::YaDeserialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($content: expr, $struct: tt, $model: expr) => {
|
($content: expr, $struct: tt, $model: expr) => {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use yaserde::YaDeserialize;
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
use yaserde::YaDeserialize;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn de_no_content() {
|
fn de_no_content() {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use yaserde::YaSerialize;
|
|
||||||
use yaserde::ser::to_string;
|
use yaserde::ser::to_string;
|
||||||
|
use yaserde::YaSerialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($model:expr, $content:expr) => {
|
($model:expr, $content:expr) => {
|
||||||
@ -19,7 +19,11 @@ macro_rules! convert_and_validate {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_struct_namespace() {
|
fn ser_struct_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
#[yaserde(
|
||||||
|
root = "root",
|
||||||
|
prefix = "ns",
|
||||||
|
namespace = "ns: http://www.sample.com/ns/domain"
|
||||||
|
)]
|
||||||
pub struct XmlStruct {
|
pub struct XmlStruct {
|
||||||
#[yaserde(prefix = "ns")]
|
#[yaserde(prefix = "ns")]
|
||||||
item: String,
|
item: String,
|
||||||
@ -36,7 +40,11 @@ fn ser_struct_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_enum_namespace() {
|
fn ser_enum_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", prefix = "ns", namespace = "ns: http://www.sample.com/ns/domain")]
|
#[yaserde(
|
||||||
|
root = "root",
|
||||||
|
prefix = "ns",
|
||||||
|
namespace = "ns: http://www.sample.com/ns/domain"
|
||||||
|
)]
|
||||||
pub enum XmlStruct {
|
pub enum XmlStruct {
|
||||||
#[yaserde(prefix = "ns")]
|
#[yaserde(prefix = "ns")]
|
||||||
Item,
|
Item,
|
||||||
@ -51,8 +59,11 @@ fn ser_enum_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_struct_multi_namespace() {
|
fn ser_struct_multi_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
#[yaserde(
|
||||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
root = "root",
|
||||||
|
namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||||
|
namespace = "ns2: http://www.sample.com/ns/domain2"
|
||||||
|
)]
|
||||||
pub struct XmlStruct {
|
pub struct XmlStruct {
|
||||||
#[yaserde(prefix = "ns1")]
|
#[yaserde(prefix = "ns1")]
|
||||||
item_1: String,
|
item_1: String,
|
||||||
@ -72,8 +83,11 @@ fn ser_struct_multi_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_enum_multi_namespace() {
|
fn ser_enum_multi_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
#[yaserde(
|
||||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
root = "root",
|
||||||
|
namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||||
|
namespace = "ns2: http://www.sample.com/ns/domain2"
|
||||||
|
)]
|
||||||
pub enum XmlStruct {
|
pub enum XmlStruct {
|
||||||
#[yaserde(prefix = "ns1")]
|
#[yaserde(prefix = "ns1")]
|
||||||
Item1,
|
Item1,
|
||||||
@ -92,8 +106,11 @@ fn ser_enum_multi_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_struct_attribute_namespace() {
|
fn ser_struct_attribute_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "root", namespace = "ns1: http://www.sample.com/ns/domain1",
|
#[yaserde(
|
||||||
namespace = "ns2: http://www.sample.com/ns/domain2")]
|
root = "root",
|
||||||
|
namespace = "ns1: http://www.sample.com/ns/domain1",
|
||||||
|
namespace = "ns2: http://www.sample.com/ns/domain2"
|
||||||
|
)]
|
||||||
pub struct XmlStruct {
|
pub struct XmlStruct {
|
||||||
#[yaserde(prefix = "ns1")]
|
#[yaserde(prefix = "ns1")]
|
||||||
item_1: String,
|
item_1: String,
|
||||||
@ -113,8 +130,11 @@ fn ser_struct_attribute_namespace() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn ser_struct_default_namespace() {
|
fn ser_struct_default_namespace() {
|
||||||
#[derive(YaSerialize, PartialEq, Debug)]
|
#[derive(YaSerialize, PartialEq, Debug)]
|
||||||
#[yaserde(root = "tt", namespace = "http://www.w3.org/ns/ttml",
|
#[yaserde(
|
||||||
namespace = "ttm: http://www.w3.org/ns/ttml#metadata")]
|
root = "tt",
|
||||||
|
namespace = "http://www.w3.org/ns/ttml",
|
||||||
|
namespace = "ttm: http://www.w3.org/ns/ttml#metadata"
|
||||||
|
)]
|
||||||
pub struct XmlStruct {
|
pub struct XmlStruct {
|
||||||
item: String,
|
item: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use yaserde::YaSerialize;
|
|
||||||
use yaserde::ser::to_string;
|
use yaserde::ser::to_string;
|
||||||
|
use yaserde::YaSerialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($type: ty, $value: expr, $content: expr) => {{
|
($type: ty, $value: expr, $content: expr) => {{
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use yaserde::YaSerialize;
|
|
||||||
use yaserde::ser::to_string;
|
use yaserde::ser::to_string;
|
||||||
|
use yaserde::YaSerialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($type: ty, $value: expr, $content: expr) => {{
|
($type: ty, $value: expr, $content: expr) => {{
|
||||||
@ -22,7 +22,8 @@ macro_rules! convert_and_validate {
|
|||||||
let content = if $content == "" {
|
let content = if $content == "" {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data />")
|
||||||
} else {
|
} else {
|
||||||
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>") + $content
|
String::from("<?xml version=\"1.0\" encoding=\"utf-8\"?><data><item>")
|
||||||
|
+ $content
|
||||||
+ "</item></data>"
|
+ "</item></data>"
|
||||||
};
|
};
|
||||||
assert_eq!(data, Ok(content));
|
assert_eq!(data, Ok(content));
|
||||||
|
|||||||
@ -6,8 +6,8 @@ extern crate yaserde;
|
|||||||
extern crate yaserde_derive;
|
extern crate yaserde_derive;
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use yaserde::YaSerialize;
|
|
||||||
use yaserde::ser::to_string;
|
use yaserde::ser::to_string;
|
||||||
|
use yaserde::YaSerialize;
|
||||||
|
|
||||||
macro_rules! convert_and_validate {
|
macro_rules! convert_and_validate {
|
||||||
($model: expr, $content: expr) => {
|
($model: expr, $content: expr) => {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
use proc_macro2::TokenTree;
|
|
||||||
use proc_macro2::Delimiter;
|
|
||||||
use proc_macro2::token_stream::IntoIter;
|
use proc_macro2::token_stream::IntoIter;
|
||||||
|
use proc_macro2::Delimiter;
|
||||||
|
use proc_macro2::TokenTree;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use syn::Attribute;
|
use syn::Attribute;
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use attribute::*;
|
use attribute::*;
|
||||||
use field_type::*;
|
use field_type::*;
|
||||||
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::TokenStreamExt;
|
use quote::TokenStreamExt;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use syn::DataEnum;
|
||||||
use syn::Fields;
|
use syn::Fields;
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
use syn::DataEnum;
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
|
||||||
|
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
data_enum: &DataEnum,
|
data_enum: &DataEnum,
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
use attribute::*;
|
use attribute::*;
|
||||||
use field_type::*;
|
use field_type::*;
|
||||||
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::TokenStreamExt;
|
use quote::TokenStreamExt;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use syn::Ident;
|
|
||||||
use syn::DataStruct;
|
use syn::DataStruct;
|
||||||
use proc_macro2::{Span, TokenStream};
|
use syn::Ident;
|
||||||
|
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
data_struct: &DataStruct,
|
data_struct: &DataStruct,
|
||||||
|
|||||||
@ -36,20 +36,15 @@ impl FieldType {
|
|||||||
"u64" => Some(FieldType::FieldTypeU64),
|
"u64" => Some(FieldType::FieldTypeU64),
|
||||||
"f32" => Some(FieldType::FieldTypeF32),
|
"f32" => Some(FieldType::FieldTypeF32),
|
||||||
"f64" => Some(FieldType::FieldTypeF64),
|
"f64" => Some(FieldType::FieldTypeF64),
|
||||||
"Option" => get_sub_type(t).map(|data_type| {
|
"Option" => get_sub_type(t).map(|data_type| FieldType::FieldTypeOption {
|
||||||
FieldType::FieldTypeOption {
|
|
||||||
data_type: Box::new(FieldType::from_ident(&data_type).unwrap()),
|
data_type: Box::new(FieldType::from_ident(&data_type).unwrap()),
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
"Vec" => get_sub_type(t).map(|data_type| {
|
"Vec" => get_sub_type(t).map(|data_type| FieldType::FieldTypeVec {
|
||||||
FieldType::FieldTypeVec {
|
|
||||||
data_type: Box::new(FieldType::from_ident(&data_type).unwrap()),
|
data_type: Box::new(FieldType::from_ident(&data_type).unwrap()),
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
_struct_name => {
|
_struct_name => Some(FieldType::FieldTypeStruct {
|
||||||
Some(FieldType::FieldTypeStruct {
|
|
||||||
struct_name: t.ident.clone(),
|
struct_name: t.ident.clone(),
|
||||||
})},
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,11 +57,9 @@ pub fn get_field_type(field: &syn::Field) -> Option<FieldType> {
|
|||||||
}
|
}
|
||||||
match path.path.segments.first() {
|
match path.path.segments.first() {
|
||||||
Some(Pair::End(t)) => FieldType::from_ident(t),
|
Some(Pair::End(t)) => FieldType::from_ident(t),
|
||||||
_ => {
|
_ => None,
|
||||||
None
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@ extern crate quote;
|
|||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|
||||||
mod attribute;
|
mod attribute;
|
||||||
mod field_type;
|
|
||||||
mod de;
|
mod de;
|
||||||
|
mod field_type;
|
||||||
mod ser;
|
mod ser;
|
||||||
|
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use attribute::*;
|
use attribute::*;
|
||||||
use field_type::*;
|
use field_type::*;
|
||||||
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::TokenStreamExt;
|
use quote::TokenStreamExt;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use syn::DataEnum;
|
||||||
use syn::Fields;
|
use syn::Fields;
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
use syn::DataEnum;
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
|
||||||
|
|
||||||
pub fn serialize(
|
pub fn serialize(
|
||||||
data_enum: &DataEnum,
|
data_enum: &DataEnum,
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
use attribute::*;
|
use attribute::*;
|
||||||
use field_type::*;
|
use field_type::*;
|
||||||
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::TokenStreamExt;
|
use quote::TokenStreamExt;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use syn::Ident;
|
|
||||||
use syn::DataStruct;
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
use syn::DataStruct;
|
||||||
|
use syn::Ident;
|
||||||
|
|
||||||
pub fn serialize(
|
pub fn serialize(
|
||||||
data_struct: &DataStruct,
|
data_struct: &DataStruct,
|
||||||
@ -93,8 +93,7 @@ pub fn serialize(
|
|||||||
struct_start_event
|
struct_start_event
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
Some(&FieldType::FieldTypeVec{..}) => {
|
Some(&FieldType::FieldTypeVec { .. }) => Some(quote!{
|
||||||
Some(quote!{
|
|
||||||
for item in &self.#label {
|
for item in &self.#label {
|
||||||
let start_event = XmlEvent::start_element(#label_name);
|
let start_event = XmlEvent::start_element(#label_name);
|
||||||
let _ret = writer.write(start_event);
|
let _ret = writer.write(start_event);
|
||||||
@ -105,8 +104,7 @@ pub fn serialize(
|
|||||||
let end_event = XmlEvent::end_element();
|
let end_event = XmlEvent::end_element();
|
||||||
let _ret = writer.write(end_event);
|
let _ret = writer.write(end_event);
|
||||||
}
|
}
|
||||||
})
|
}),
|
||||||
}
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,8 +263,7 @@ pub fn serialize(
|
|||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(FieldType::FieldTypeStruct { .. }) => {
|
Some(FieldType::FieldTypeStruct { .. }) => Some(quote!{
|
||||||
Some(quote!{
|
|
||||||
writer.set_skip_start_end(false);
|
writer.set_skip_start_end(false);
|
||||||
match self.#label.serialize(writer) {
|
match self.#label.serialize(writer) {
|
||||||
Ok(()) => {},
|
Ok(()) => {},
|
||||||
@ -274,8 +271,7 @@ pub fn serialize(
|
|||||||
return Err(msg);
|
return Err(msg);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})
|
}),
|
||||||
},
|
|
||||||
Some(FieldType::FieldTypeVec { data_type }) => {
|
Some(FieldType::FieldTypeVec { data_type }) => {
|
||||||
let dt = Box::into_raw(data_type);
|
let dt = Box::into_raw(data_type);
|
||||||
match unsafe { dt.as_ref() } {
|
match unsafe { dt.as_ref() } {
|
||||||
@ -344,7 +340,7 @@ pub fn serialize(
|
|||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user