remove clippy messages to clean code
This commit is contained in:
parent
d63e9d27d8
commit
c87d0faa02
@ -26,7 +26,7 @@ fn get_value(iter: &mut TokenTreeIter) -> Option<String> {
|
||||
}
|
||||
|
||||
impl YaSerdeAttribute {
|
||||
pub fn parse(attrs: &Vec<Attribute>) -> YaSerdeAttribute {
|
||||
pub fn parse(attrs: &[Attribute]) -> YaSerdeAttribute {
|
||||
let mut attribute = false;
|
||||
let mut namespaces = BTreeMap::new();
|
||||
let mut prefix = None;
|
||||
@ -36,59 +36,54 @@ impl YaSerdeAttribute {
|
||||
|
||||
for attr in attrs.iter() {
|
||||
let mut attr_iter = attr.clone().tts.into_iter();
|
||||
match attr_iter.next() {
|
||||
Some(token) => match token.kind {
|
||||
Group(Parenthesis, token_stream) => {
|
||||
let mut attr_iter = token_stream.into_iter();
|
||||
if let Some(token) = attr_iter.next() {
|
||||
if let Group(Parenthesis, token_stream) = token.kind {
|
||||
let mut attr_iter = token_stream.into_iter();
|
||||
|
||||
while let Some(item) = attr_iter.next() {
|
||||
match item.kind {
|
||||
Term(t) => match t.as_str() {
|
||||
"attribute" => {
|
||||
attribute = true;
|
||||
}
|
||||
"namespace" => {
|
||||
if let Some(namespace) = get_value(&mut attr_iter) {
|
||||
let splitted: Vec<&str> = namespace.split(": ").collect();
|
||||
if splitted.len() == 2 {
|
||||
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
|
||||
}
|
||||
if splitted.len() == 1 {
|
||||
namespaces.insert("".to_owned(), splitted[0].to_owned());
|
||||
}
|
||||
while let Some(item) = attr_iter.next() {
|
||||
if let Term(term) = item.kind {
|
||||
match term.as_str() {
|
||||
"attribute" => {
|
||||
attribute = true;
|
||||
}
|
||||
"namespace" => {
|
||||
if let Some(namespace) = get_value(&mut attr_iter) {
|
||||
let splitted: Vec<&str> = namespace.split(": ").collect();
|
||||
if splitted.len() == 2 {
|
||||
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
|
||||
}
|
||||
if splitted.len() == 1 {
|
||||
namespaces.insert("".to_owned(), splitted[0].to_owned());
|
||||
}
|
||||
}
|
||||
"prefix" => {
|
||||
prefix = get_value(&mut attr_iter);
|
||||
}
|
||||
"rename" => {
|
||||
rename = get_value(&mut attr_iter);
|
||||
}
|
||||
"root" => {
|
||||
root = get_value(&mut attr_iter);
|
||||
}
|
||||
"text" => {
|
||||
text = true;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
"prefix" => {
|
||||
prefix = get_value(&mut attr_iter);
|
||||
}
|
||||
"rename" => {
|
||||
rename = get_value(&mut attr_iter);
|
||||
}
|
||||
"root" => {
|
||||
root = get_value(&mut attr_iter);
|
||||
}
|
||||
"text" => {
|
||||
text = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
YaSerdeAttribute {
|
||||
attribute: attribute,
|
||||
namespaces: namespaces,
|
||||
prefix: prefix,
|
||||
rename: rename,
|
||||
root: root,
|
||||
text: text,
|
||||
attribute,
|
||||
namespaces,
|
||||
prefix,
|
||||
rename,
|
||||
root,
|
||||
text,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ use proc_macro2::Span;
|
||||
pub fn parse(
|
||||
data_enum: &DataEnum,
|
||||
name: &Ident,
|
||||
root: &String,
|
||||
root: &str,
|
||||
_namespaces: &BTreeMap<String, String>,
|
||||
) -> Tokens {
|
||||
let variables: Tokens = data_enum
|
||||
@ -27,34 +27,34 @@ pub fn parse(
|
||||
|
||||
match get_field_type(field) {
|
||||
Some(FieldType::FieldTypeString) => {
|
||||
build_default_value(&field_label, quote!{String}, quote!{"".to_string()})
|
||||
build_default_value(&field_label, "e!{String}, "e!{"".to_string()})
|
||||
}
|
||||
Some(FieldType::FieldTypeBool) => {
|
||||
build_default_value(&field_label, quote!{bool}, quote!{false})
|
||||
build_default_value(&field_label, "e!{bool}, "e!{false})
|
||||
}
|
||||
Some(FieldType::FieldTypeI8) => {
|
||||
build_default_value(&field_label, quote!{i8}, quote!{0})
|
||||
build_default_value(&field_label, "e!{i8}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeU8) => {
|
||||
build_default_value(&field_label, quote!{u8}, quote!{0})
|
||||
build_default_value(&field_label, "e!{u8}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeI16) => {
|
||||
build_default_value(&field_label, quote!{i16}, quote!{0})
|
||||
build_default_value(&field_label, "e!{i16}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeU16) => {
|
||||
build_default_value(&field_label, quote!{u16}, quote!{0})
|
||||
build_default_value(&field_label, "e!{u16}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeI32) => {
|
||||
build_default_value(&field_label, quote!{i32}, quote!{0})
|
||||
build_default_value(&field_label, "e!{i32}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeU32) => {
|
||||
build_default_value(&field_label, quote!{u32}, quote!{0})
|
||||
build_default_value(&field_label, "e!{u32}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeI64) => {
|
||||
build_default_value(&field_label, quote!{i64}, quote!{0})
|
||||
build_default_value(&field_label, "e!{i64}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeU64) => {
|
||||
build_default_value(&field_label, quote!{u64}, quote!{0})
|
||||
build_default_value(&field_label, "e!{u64}, "e!{0})
|
||||
}
|
||||
Some(FieldType::FieldTypeStruct { struct_name }) => Some(quote!{
|
||||
#[allow(unused_mut)]
|
||||
@ -64,34 +64,34 @@ pub fn parse(
|
||||
let dt = Box::into_raw(data_type);
|
||||
match unsafe { dt.as_ref() } {
|
||||
Some(&FieldType::FieldTypeString) => {
|
||||
build_default_value(&field_label, quote!{Vec<String>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<String>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeBool) => {
|
||||
build_default_value(&field_label, quote!{Vec<bool>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<bool>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI8) => {
|
||||
build_default_value(&field_label, quote!{Vec<i8>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<i8>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU8) => {
|
||||
build_default_value(&field_label, quote!{Vec<u8>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<u8>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI16) => {
|
||||
build_default_value(&field_label, quote!{Vec<i16>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<i16>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU16) => {
|
||||
build_default_value(&field_label, quote!{Vec<u16>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<u16>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI32) => {
|
||||
build_default_value(&field_label, quote!{Vec<i32>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<i32>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU32) => {
|
||||
build_default_value(&field_label, quote!{Vec<u32>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<u32>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI64) => {
|
||||
build_default_value(&field_label, quote!{Vec<i64>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<i64>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU64) => {
|
||||
build_default_value(&field_label, quote!{Vec<u64>}, quote!{vec![]})
|
||||
build_default_value(&field_label, "e!{Vec<u64>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { struct_name }) => Some(quote!{
|
||||
#[allow(unused_mut)]
|
||||
@ -274,8 +274,8 @@ pub fn parse(
|
||||
|
||||
fn build_default_value(
|
||||
label: &Option<Ident>,
|
||||
field_type: Tokens,
|
||||
default: Tokens,
|
||||
field_type: &Tokens,
|
||||
default: &Tokens,
|
||||
) -> Option<Tokens> {
|
||||
Some(quote!{
|
||||
#[allow(unused_mut)]
|
||||
|
||||
@ -9,7 +9,7 @@ use proc_macro2::Span;
|
||||
pub fn parse(
|
||||
data_struct: &DataStruct,
|
||||
name: &Ident,
|
||||
root: &String,
|
||||
root: &str,
|
||||
namespaces: &BTreeMap<String, String>,
|
||||
) -> Tokens {
|
||||
let validate_namespace: Tokens = namespaces
|
||||
@ -43,17 +43,19 @@ pub fn parse(
|
||||
let label = field.ident;
|
||||
match get_field_type(field) {
|
||||
Some(FieldType::FieldTypeString) => {
|
||||
build_default_value(&label, quote!{String}, quote!{"".to_string()})
|
||||
build_default_value(&label, "e!{String}, "e!{"".to_string()})
|
||||
}
|
||||
Some(FieldType::FieldTypeBool) => build_default_value(&label, quote!{bool}, quote!{false}),
|
||||
Some(FieldType::FieldTypeI8) => build_default_value(&label, quote!{i8}, quote!{0}),
|
||||
Some(FieldType::FieldTypeU8) => build_default_value(&label, quote!{u8}, quote!{0}),
|
||||
Some(FieldType::FieldTypeI16) => build_default_value(&label, quote!{i16}, quote!{0}),
|
||||
Some(FieldType::FieldTypeU16) => build_default_value(&label, quote!{u16}, quote!{0}),
|
||||
Some(FieldType::FieldTypeI32) => build_default_value(&label, quote!{i32}, quote!{0}),
|
||||
Some(FieldType::FieldTypeU32) => build_default_value(&label, quote!{u32}, quote!{0}),
|
||||
Some(FieldType::FieldTypeI64) => build_default_value(&label, quote!{i64}, quote!{0}),
|
||||
Some(FieldType::FieldTypeU64) => build_default_value(&label, quote!{u64}, quote!{0}),
|
||||
Some(FieldType::FieldTypeBool) => {
|
||||
build_default_value(&label, "e!{bool}, "e!{false})
|
||||
}
|
||||
Some(FieldType::FieldTypeI8) => build_default_value(&label, "e!{i8}, "e!{0}),
|
||||
Some(FieldType::FieldTypeU8) => build_default_value(&label, "e!{u8}, "e!{0}),
|
||||
Some(FieldType::FieldTypeI16) => build_default_value(&label, "e!{i16}, "e!{0}),
|
||||
Some(FieldType::FieldTypeU16) => build_default_value(&label, "e!{u16}, "e!{0}),
|
||||
Some(FieldType::FieldTypeI32) => build_default_value(&label, "e!{i32}, "e!{0}),
|
||||
Some(FieldType::FieldTypeU32) => build_default_value(&label, "e!{u32}, "e!{0}),
|
||||
Some(FieldType::FieldTypeI64) => build_default_value(&label, "e!{i64}, "e!{0}),
|
||||
Some(FieldType::FieldTypeU64) => build_default_value(&label, "e!{u64}, "e!{0}),
|
||||
Some(FieldType::FieldTypeStruct { struct_name }) => Some(quote!{
|
||||
#[allow(unused_mut, non_snake_case, non_camel_case_types)]
|
||||
let mut #label : #struct_name = #struct_name::default();
|
||||
@ -62,34 +64,34 @@ pub fn parse(
|
||||
let dt = Box::into_raw(data_type);
|
||||
match unsafe { dt.as_ref() } {
|
||||
Some(&FieldType::FieldTypeString) => {
|
||||
build_default_value(&label, quote!{Vec<String>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<String>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeBool) => {
|
||||
build_default_value(&label, quote!{Vec<bool>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<bool>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI8) => {
|
||||
build_default_value(&label, quote!{Vec<i8>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<i8>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU8) => {
|
||||
build_default_value(&label, quote!{Vec<u8>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<u8>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI16) => {
|
||||
build_default_value(&label, quote!{Vec<i16>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<i16>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU16) => {
|
||||
build_default_value(&label, quote!{Vec<u16>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<u16>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI32) => {
|
||||
build_default_value(&label, quote!{Vec<i32>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<i32>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU32) => {
|
||||
build_default_value(&label, quote!{Vec<u32>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<u32>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeI64) => {
|
||||
build_default_value(&label, quote!{Vec<i64>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<i64>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeU64) => {
|
||||
build_default_value(&label, quote!{Vec<u64>}, quote!{vec![]})
|
||||
build_default_value(&label, "e!{Vec<u64>}, "e!{vec![]})
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { struct_name }) => Some(quote!{
|
||||
#[allow(unused_mut)]
|
||||
@ -129,43 +131,43 @@ pub fn parse(
|
||||
match get_field_type(field) {
|
||||
Some(FieldType::FieldTypeString) => {
|
||||
let visitor = Ident::new("visit_str", Span::call_site());
|
||||
build_declare_visitor(quote!{String}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{String}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeBool) => {
|
||||
let visitor = Ident::new("visit_bool", Span::call_site());
|
||||
build_declare_visitor(quote!{bool}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{bool}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeI8) => {
|
||||
let visitor = Ident::new("visit_i8", Span::call_site());
|
||||
build_declare_visitor(quote!{i8}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i8}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeU8) => {
|
||||
let visitor = Ident::new("visit_u8", Span::call_site());
|
||||
build_declare_visitor(quote!{u8}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u8}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeI16) => {
|
||||
let visitor = Ident::new("visit_i16", Span::call_site());
|
||||
build_declare_visitor(quote!{i16}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i16}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeU16) => {
|
||||
let visitor = Ident::new("visit_u16", Span::call_site());
|
||||
build_declare_visitor(quote!{u16}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u16}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeI32) => {
|
||||
let visitor = Ident::new("visit_i32", Span::call_site());
|
||||
build_declare_visitor(quote!{i32}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i32}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeU32) => {
|
||||
let visitor = Ident::new("visit_u32", Span::call_site());
|
||||
build_declare_visitor(quote!{u32}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u32}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeI64) => {
|
||||
let visitor = Ident::new("visit_i64", Span::call_site());
|
||||
build_declare_visitor(quote!{i64}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i64}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeU64) => {
|
||||
let visitor = Ident::new("visit_u64", Span::call_site());
|
||||
build_declare_visitor(quote!{u64}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u64}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeStruct { struct_name }) => {
|
||||
let struct_id = struct_name.to_string();
|
||||
@ -193,43 +195,43 @@ pub fn parse(
|
||||
match unsafe { dt.as_ref() } {
|
||||
Some(&FieldType::FieldTypeString) => {
|
||||
let visitor = Ident::new("visit_str", Span::call_site());
|
||||
build_declare_visitor(quote!{String}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{String}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeBool) => {
|
||||
let visitor = Ident::new("visit_bool", Span::call_site());
|
||||
build_declare_visitor(quote!{bool}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{bool}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeI8) => {
|
||||
let visitor = Ident::new("visit_i8", Span::call_site());
|
||||
build_declare_visitor(quote!{i8}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i8}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeU8) => {
|
||||
let visitor = Ident::new("visit_u8", Span::call_site());
|
||||
build_declare_visitor(quote!{u8}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u8}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeI16) => {
|
||||
let visitor = Ident::new("visit_i16", Span::call_site());
|
||||
build_declare_visitor(quote!{i16}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i16}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeU16) => {
|
||||
let visitor = Ident::new("visit_u16", Span::call_site());
|
||||
build_declare_visitor(quote!{u16}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u16}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeI32) => {
|
||||
let visitor = Ident::new("visit_i32", Span::call_site());
|
||||
build_declare_visitor(quote!{i32}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i32}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeU32) => {
|
||||
let visitor = Ident::new("visit_u32", Span::call_site());
|
||||
build_declare_visitor(quote!{u32}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u32}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeI64) => {
|
||||
let visitor = Ident::new("visit_i64", Span::call_site());
|
||||
build_declare_visitor(quote!{i64}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{i64}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeU64) => {
|
||||
let visitor = Ident::new("visit_u64", Span::call_site());
|
||||
build_declare_visitor(quote!{u64}, &visitor, &visitor_label)
|
||||
build_declare_visitor("e!{u64}, &visitor, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { struct_name }) => {
|
||||
let struct_ident = Ident::new(&format!("{}", struct_name), Span::def_site());
|
||||
@ -277,9 +279,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeString) => {
|
||||
let visitor = Ident::new("visit_str", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{String},
|
||||
"e!{String},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -288,9 +290,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeBool) => {
|
||||
let visitor = Ident::new("visit_bool", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{bool},
|
||||
"e!{bool},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -299,9 +301,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeI8) => {
|
||||
let visitor = Ident::new("visit_i8", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i8},
|
||||
"e!{i8},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -310,9 +312,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeU8) => {
|
||||
let visitor = Ident::new("visit_u8", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u8},
|
||||
"e!{u8},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -321,9 +323,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeU16) => {
|
||||
let visitor = Ident::new("visit_u16", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u16},
|
||||
"e!{u16},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -332,9 +334,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeI16) => {
|
||||
let visitor = Ident::new("visit_i16", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i16},
|
||||
"e!{i16},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -343,9 +345,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeU32) => {
|
||||
let visitor = Ident::new("visit_u32", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u32},
|
||||
"e!{u32},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -354,9 +356,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeI32) => {
|
||||
let visitor = Ident::new("visit_i32", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i32},
|
||||
"e!{i32},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -365,9 +367,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeU64) => {
|
||||
let visitor = Ident::new("visit_u64", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u64},
|
||||
"e!{u64},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -376,9 +378,9 @@ pub fn parse(
|
||||
Some(FieldType::FieldTypeI64) => {
|
||||
let visitor = Ident::new("visit_i64", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i64},
|
||||
"e!{i64},
|
||||
&visitor,
|
||||
quote!{= value},
|
||||
"e!{= value},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -404,9 +406,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeString) => {
|
||||
let visitor = Ident::new("visit_str", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{String},
|
||||
"e!{String},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -415,9 +417,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeBool) => {
|
||||
let visitor = Ident::new("visit_bool", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{bool},
|
||||
"e!{bool},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -426,9 +428,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeI8) => {
|
||||
let visitor = Ident::new("visit_i8", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i8},
|
||||
"e!{i8},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -437,9 +439,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeU8) => {
|
||||
let visitor = Ident::new("visit_u8", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u8},
|
||||
"e!{u8},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -448,9 +450,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeI16) => {
|
||||
let visitor = Ident::new("visit_i16", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i16},
|
||||
"e!{i16},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -459,9 +461,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeU16) => {
|
||||
let visitor = Ident::new("visit_u16", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u16},
|
||||
"e!{u16},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -470,9 +472,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeI32) => {
|
||||
let visitor = Ident::new("visit_i32", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i32},
|
||||
"e!{i32},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -481,9 +483,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeU32) => {
|
||||
let visitor = Ident::new("visit_u32", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u32},
|
||||
"e!{u32},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -492,9 +494,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeI64) => {
|
||||
let visitor = Ident::new("visit_i64", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{i64},
|
||||
"e!{i64},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -503,9 +505,9 @@ pub fn parse(
|
||||
Some(&FieldType::FieldTypeU64) => {
|
||||
let visitor = Ident::new("visit_u64", Span::call_site());
|
||||
build_call_visitor(
|
||||
quote!{u64},
|
||||
"e!{u64},
|
||||
&visitor,
|
||||
quote!{.push(value)},
|
||||
"e!{.push(value)},
|
||||
&visitor_label,
|
||||
&label,
|
||||
&label_name,
|
||||
@ -602,52 +604,52 @@ pub fn parse(
|
||||
|
||||
match get_field_type(field) {
|
||||
Some(FieldType::FieldTypeString) => {
|
||||
build_set_text_to_value(&field_attrs, &label, quote!{text_content.to_owned()})
|
||||
build_set_text_to_value(&field_attrs, &label, "e!{text_content.to_owned()})
|
||||
}
|
||||
Some(FieldType::FieldTypeBool) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{bool::from_str(text_content).unwrap()},
|
||||
"e!{bool::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeI8) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{i8::from_str(text_content).unwrap()},
|
||||
"e!{i8::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeU8) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{u8::from_str(text_content).unwrap()},
|
||||
"e!{u8::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeI16) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{i16::from_str(text_content).unwrap()},
|
||||
"e!{i16::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeU16) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{u16::from_str(text_content).unwrap()},
|
||||
"e!{u16::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeI32) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{i32::from_str(text_content).unwrap()},
|
||||
"e!{i32::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeU32) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{u32::from_str(text_content).unwrap()},
|
||||
"e!{u32::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeI64) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{i64::from_str(text_content).unwrap()},
|
||||
"e!{i64::from_str(text_content).unwrap()},
|
||||
),
|
||||
Some(FieldType::FieldTypeU64) => build_set_text_to_value(
|
||||
&field_attrs,
|
||||
&label,
|
||||
quote!{u64::from_str(text_content).unwrap()},
|
||||
"e!{u64::from_str(text_content).unwrap()},
|
||||
),
|
||||
|
||||
Some(FieldType::FieldTypeStruct { .. }) | Some(FieldType::FieldTypeVec { .. }) | None => {
|
||||
@ -743,8 +745,8 @@ pub fn parse(
|
||||
|
||||
fn build_default_value(
|
||||
label: &Option<Ident>,
|
||||
field_type: Tokens,
|
||||
default: Tokens,
|
||||
field_type: &Tokens,
|
||||
default: &Tokens,
|
||||
) -> Option<Tokens> {
|
||||
Some(quote!{
|
||||
#[allow(unused_mut)]
|
||||
@ -753,7 +755,7 @@ fn build_default_value(
|
||||
}
|
||||
|
||||
fn build_declare_visitor(
|
||||
field_type: Tokens,
|
||||
field_type: &Tokens,
|
||||
visitor: &Ident,
|
||||
visitor_label: &Ident,
|
||||
) -> Option<Tokens> {
|
||||
@ -771,12 +773,12 @@ fn build_declare_visitor(
|
||||
}
|
||||
|
||||
fn build_call_visitor(
|
||||
field_type: Tokens,
|
||||
field_type: &Tokens,
|
||||
visitor: &Ident,
|
||||
action: Tokens,
|
||||
action: &Tokens,
|
||||
visitor_label: &Ident,
|
||||
label: &Option<Ident>,
|
||||
label_name: &String,
|
||||
label_name: &str,
|
||||
) -> Option<Tokens> {
|
||||
Some(quote!{
|
||||
#label_name => {
|
||||
@ -799,7 +801,6 @@ fn build_call_visitor(
|
||||
});
|
||||
|
||||
if let Ok(value) = result {
|
||||
// #label = value
|
||||
#label#action
|
||||
}
|
||||
}
|
||||
@ -809,7 +810,7 @@ fn build_call_visitor(
|
||||
fn build_set_text_to_value(
|
||||
field_attrs: &YaSerdeAttribute,
|
||||
label: &Option<Ident>,
|
||||
action: Tokens,
|
||||
action: &Tokens,
|
||||
) -> Option<Tokens> {
|
||||
if field_attrs.text {
|
||||
Some(quote!{
|
||||
|
||||
@ -13,16 +13,16 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<quote::Tokens
|
||||
let data = &ast.data;
|
||||
|
||||
let root_attrs = attribute::YaSerdeAttribute::parse(&attrs);
|
||||
let root = root_attrs.clone().root.unwrap_or(name.to_string());
|
||||
let root = root_attrs.clone().root.unwrap_or_else(|| name.to_string());
|
||||
|
||||
let impl_block = match data {
|
||||
&syn::Data::Struct(ref data_struct) => {
|
||||
let impl_block = match *data {
|
||||
syn::Data::Struct(ref data_struct) => {
|
||||
expand_struct::parse(data_struct, &name, &root, &root_attrs.namespaces)
|
||||
}
|
||||
&syn::Data::Enum(ref data_enum) => {
|
||||
syn::Data::Enum(ref data_enum) => {
|
||||
expand_enum::parse(data_enum, &name, &root, &root_attrs.namespaces)
|
||||
}
|
||||
&syn::Data::Union(ref _data_union) => unimplemented!(),
|
||||
syn::Data::Union(ref _data_union) => unimplemented!(),
|
||||
};
|
||||
|
||||
let dummy_const = Ident::new(
|
||||
|
||||
@ -61,8 +61,8 @@ pub fn get_field_type(field: &syn::Field) -> Option<FieldType> {
|
||||
fn get_vec_type(t: &syn::PathSegment) -> Option<syn::Ident> {
|
||||
if let syn::PathArguments::AngleBracketed(ref args) = t.arguments {
|
||||
if let Some(Pair::End(tt)) = args.args.first() {
|
||||
if let &syn::GenericArgument::Type(ref argument) = tt {
|
||||
if let &Path(ref path2) = argument {
|
||||
if let syn::GenericArgument::Type(ref argument) = *tt {
|
||||
if let Path(ref path2) = argument {
|
||||
if let Some(Pair::End(ttt)) = path2.path.segments.first() {
|
||||
return Some(ttt.ident);
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ use proc_macro2::Span;
|
||||
pub fn serialize(
|
||||
data_enum: &DataEnum,
|
||||
name: &Ident,
|
||||
root: &String,
|
||||
root: &str,
|
||||
namespaces: &BTreeMap<String, String>,
|
||||
) -> Tokens {
|
||||
let write_enum_content: Tokens = data_enum
|
||||
@ -42,12 +42,12 @@ pub fn serialize(
|
||||
.iter()
|
||||
.map(|ref field| {
|
||||
let field_attrs = YaSerdeAttribute::parse(&field.attrs);
|
||||
if field_attrs.attribute == true {
|
||||
if field_attrs.attribute {
|
||||
return None;
|
||||
}
|
||||
|
||||
let field_label = field.ident;
|
||||
if field_attrs.text == true {
|
||||
if field_attrs.text {
|
||||
return Some(quote!(
|
||||
let data_event = XmlEvent::characters(&self.#field_label);
|
||||
let _ret = writer.write(data_event);
|
||||
|
||||
@ -10,7 +10,7 @@ use std::string::ToString;
|
||||
pub fn serialize(
|
||||
data_struct: &DataStruct,
|
||||
name: &Ident,
|
||||
root: &String,
|
||||
root: &str,
|
||||
namespaces: &BTreeMap<String, String>,
|
||||
) -> Tokens {
|
||||
let build_attributes: Tokens = data_struct
|
||||
@ -18,7 +18,7 @@ pub fn serialize(
|
||||
.iter()
|
||||
.map(|ref field| {
|
||||
let field_attrs = YaSerdeAttribute::parse(&field.attrs);
|
||||
if field_attrs.attribute == false {
|
||||
if !field_attrs.attribute {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -90,12 +90,12 @@ pub fn serialize(
|
||||
.iter()
|
||||
.map(|ref field| {
|
||||
let field_attrs = YaSerdeAttribute::parse(&field.attrs);
|
||||
if field_attrs.attribute == true {
|
||||
if field_attrs.attribute {
|
||||
return None;
|
||||
}
|
||||
|
||||
let label = field.ident;
|
||||
if field_attrs.text == true {
|
||||
if field_attrs.text {
|
||||
return Some(quote!(
|
||||
let data_event = XmlEvent::characters(&self.#label);
|
||||
let _ret = writer.write(data_event);
|
||||
|
||||
@ -13,7 +13,7 @@ pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<quote::Tokens,
|
||||
let data = &ast.data;
|
||||
|
||||
let root_attrs = attribute::YaSerdeAttribute::parse(&attrs);
|
||||
let root = root_attrs.clone().root.unwrap_or(name.to_string());
|
||||
let root = root_attrs.clone().root.unwrap_or_else(|| name.to_string());
|
||||
|
||||
let root = if let Some(prefix) = root_attrs.prefix {
|
||||
prefix + ":" + &root
|
||||
@ -21,14 +21,14 @@ pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<quote::Tokens,
|
||||
root
|
||||
};
|
||||
|
||||
let impl_block = match data {
|
||||
&syn::Data::Struct(ref data_struct) => {
|
||||
let impl_block = match *data {
|
||||
syn::Data::Struct(ref data_struct) => {
|
||||
expand_struct::serialize(data_struct, &name, &root, &root_attrs.namespaces)
|
||||
}
|
||||
&syn::Data::Enum(ref data_enum) => {
|
||||
syn::Data::Enum(ref data_enum) => {
|
||||
expand_enum::serialize(data_enum, &name, &root, &root_attrs.namespaces)
|
||||
}
|
||||
&syn::Data::Union(ref _data_union) => unimplemented!(),
|
||||
syn::Data::Union(ref _data_union) => unimplemented!(),
|
||||
};
|
||||
|
||||
let dummy_const = Ident::new(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user