move field_type to common part

This commit is contained in:
Marc-Antoine Arnaud
2018-04-10 11:25:16 +02:00
parent 61f9badbe7
commit 1c867a6ff1
5 changed files with 3 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
use attribute::*;
use de::field_type::*;
use field_type::*;
use quote::Tokens;
use syn::Ident;
use syn::DataStruct;

View File

@@ -1,70 +0,0 @@
use syn;
use syn::punctuated::Pair;
use syn::Type::Path;
#[derive(Debug)]
pub enum FieldType {
FieldTypeString,
FieldTypeVec,
FieldTypeStruct{name: String},
}
pub fn get_field_type(field: &syn::Field) -> Option<FieldType> {
match field.ty {
Path(ref path) => {
match path.path.segments.first() {
Some(Pair::End(t)) => {
match t.ident.to_string().as_str() {
"String" => Some(FieldType::FieldTypeString),
"Vec" => Some(FieldType::FieldTypeVec),
name => Some(FieldType::FieldTypeStruct{name: name.to_string()}),
}
},
_ => {
None
},
}
},
_ => {None},
}
}
pub fn get_vec_type(field: &syn::Field) -> Option<syn::Ident> {
match field.ty {
Path(ref path) => {
match path.path.segments.first() {
Some(Pair::End(t)) => {
match t.arguments {
syn::PathArguments::AngleBracketed(ref args) => {
match args.args.first() {
Some(Pair::End(tt)) => {
match tt {
&syn::GenericArgument::Type(ref argument) => {
match argument {
&Path(ref path2) => {
match path2.path.segments.first() {
Some(Pair::End(ttt)) => {
Some(ttt.ident)
},
_ => None
}
},
_ => None
}
},
_ => None
}
},
_ => None
}
},
_ => None
}
},
_ => None
}
}
_ => None
}
}

View File

@@ -1,6 +1,5 @@
pub mod expand_struct;
pub mod field_type;
use attribute;
use proc_macro2::Span;