Fix formatting
This commit is contained in:
parent
ab03d32cfb
commit
5a81a5add8
@ -2,7 +2,7 @@ use attribute::*;
|
||||
use de::build_default_value::build_default_value;
|
||||
use field_type::*;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{TokenStreamExt, ToTokens};
|
||||
use quote::{ToTokens, TokenStreamExt};
|
||||
use std::collections::BTreeMap;
|
||||
use syn::DataStruct;
|
||||
use syn::Ident;
|
||||
@ -249,7 +249,11 @@ pub fn parse(
|
||||
build_declare_visitor("e! {f64}, "e! {visit_f64}, &visitor_label)
|
||||
}
|
||||
Some(FieldType::FieldTypeStruct { struct_name }) => {
|
||||
let struct_id : String = struct_name.segments.iter().map(|s| s.ident.to_string()).collect();
|
||||
let struct_id: String = struct_name
|
||||
.segments
|
||||
.iter()
|
||||
.map(|s| s.ident.to_string())
|
||||
.collect();
|
||||
let struct_ident = Ident::new(
|
||||
&format!("__Visitor_{}_{}", label_name, struct_id),
|
||||
Span::call_site(),
|
||||
@ -309,7 +313,10 @@ pub fn parse(
|
||||
build_declare_visitor("e! {f64}, "e! {visit_f64}, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { ref struct_name }) => {
|
||||
let struct_ident = Ident::new(&format!("{}", struct_name.into_token_stream()), Span::call_site());
|
||||
let struct_ident = Ident::new(
|
||||
&format!("{}", struct_name.into_token_stream()),
|
||||
Span::call_site(),
|
||||
);
|
||||
Some(quote! {
|
||||
#[allow(non_snake_case, non_camel_case_types)]
|
||||
struct #visitor_label;
|
||||
@ -363,7 +370,10 @@ pub fn parse(
|
||||
build_declare_visitor("e! {f64}, "e! {visit_f64}, &visitor_label)
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { ref struct_name }) => {
|
||||
let struct_ident = Ident::new(&format!("{}", struct_name.into_token_stream()), Span::call_site());
|
||||
let struct_ident = Ident::new(
|
||||
&format!("{}", struct_name.into_token_stream()),
|
||||
Span::call_site(),
|
||||
);
|
||||
Some(quote! {
|
||||
#[allow(non_snake_case, non_camel_case_types)]
|
||||
struct #visitor_label;
|
||||
@ -685,7 +695,10 @@ pub fn parse(
|
||||
)
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { ref struct_name }) => {
|
||||
let struct_ident = Ident::new(&format!("{}", struct_name.into_token_stream()), Span::call_site());
|
||||
let struct_ident = Ident::new(
|
||||
&format!("{}", struct_name.into_token_stream()),
|
||||
Span::call_site(),
|
||||
);
|
||||
Some(quote! {
|
||||
#label_name => {
|
||||
reader.set_map_value();
|
||||
@ -840,7 +853,10 @@ pub fn parse(
|
||||
)
|
||||
}
|
||||
Some(&FieldType::FieldTypeStruct { ref struct_name }) => {
|
||||
let struct_ident = Ident::new(&format!("{}", struct_name.into_token_stream()), Span::call_site());
|
||||
let struct_ident = Ident::new(
|
||||
&format!("{}", struct_name.into_token_stream()),
|
||||
Span::call_site(),
|
||||
);
|
||||
Some(quote! {
|
||||
#label_name => {
|
||||
reader.set_map_value();
|
||||
@ -1064,7 +1080,11 @@ pub fn parse(
|
||||
}
|
||||
Some(FieldType::FieldTypeStruct { struct_name }) => {
|
||||
let struct_ident = Ident::new(
|
||||
&format!("__Visitor_{}_{}", label_name, struct_name.into_token_stream()),
|
||||
&format!(
|
||||
"__Visitor_{}_{}",
|
||||
label_name,
|
||||
struct_name.into_token_stream()
|
||||
),
|
||||
Span::call_site(),
|
||||
);
|
||||
|
||||
|
||||
@ -23,30 +23,28 @@ pub enum FieldType {
|
||||
impl FieldType {
|
||||
fn from_ident(path: &syn::Path) -> Option<FieldType> {
|
||||
match path.segments.last() {
|
||||
Some(t) => {
|
||||
match t.ident.to_string().as_str() {
|
||||
"String" => Some(FieldType::FieldTypeString),
|
||||
"bool" => Some(FieldType::FieldTypeBool),
|
||||
"i8" => Some(FieldType::FieldTypeI8),
|
||||
"u8" => Some(FieldType::FieldTypeU8),
|
||||
"i16" => Some(FieldType::FieldTypeI16),
|
||||
"u16" => Some(FieldType::FieldTypeU16),
|
||||
"i32" => Some(FieldType::FieldTypeI32),
|
||||
"u32" => Some(FieldType::FieldTypeU32),
|
||||
"i64" => Some(FieldType::FieldTypeI64),
|
||||
"u64" => Some(FieldType::FieldTypeU64),
|
||||
"f32" => Some(FieldType::FieldTypeF32),
|
||||
"f64" => Some(FieldType::FieldTypeF64),
|
||||
"Option" => get_sub_type(t).map(|data_type| FieldType::FieldTypeOption {
|
||||
data_type: Box::new(FieldType::from_ident(&syn::Path::from(data_type)).unwrap()),
|
||||
}),
|
||||
"Vec" => get_sub_type(t).map(|data_type| FieldType::FieldTypeVec {
|
||||
data_type: Box::new(FieldType::from_ident(&syn::Path::from(data_type)).unwrap()),
|
||||
}),
|
||||
_ => Some(FieldType::FieldTypeStruct {
|
||||
struct_name: path.clone(),
|
||||
}),
|
||||
}
|
||||
Some(t) => match t.ident.to_string().as_str() {
|
||||
"String" => Some(FieldType::FieldTypeString),
|
||||
"bool" => Some(FieldType::FieldTypeBool),
|
||||
"i8" => Some(FieldType::FieldTypeI8),
|
||||
"u8" => Some(FieldType::FieldTypeU8),
|
||||
"i16" => Some(FieldType::FieldTypeI16),
|
||||
"u16" => Some(FieldType::FieldTypeU16),
|
||||
"i32" => Some(FieldType::FieldTypeI32),
|
||||
"u32" => Some(FieldType::FieldTypeU32),
|
||||
"i64" => Some(FieldType::FieldTypeI64),
|
||||
"u64" => Some(FieldType::FieldTypeU64),
|
||||
"f32" => Some(FieldType::FieldTypeF32),
|
||||
"f64" => Some(FieldType::FieldTypeF64),
|
||||
"Option" => get_sub_type(t).map(|data_type| FieldType::FieldTypeOption {
|
||||
data_type: Box::new(FieldType::from_ident(&syn::Path::from(data_type)).unwrap()),
|
||||
}),
|
||||
"Vec" => get_sub_type(t).map(|data_type| FieldType::FieldTypeVec {
|
||||
data_type: Box::new(FieldType::from_ident(&syn::Path::from(data_type)).unwrap()),
|
||||
}),
|
||||
_ => Some(FieldType::FieldTypeStruct {
|
||||
struct_name: path.clone(),
|
||||
}),
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user