|
@@ -4,16 +4,15 @@ use syn::{parse_macro_input, DeriveInput};
|
|
|
|
|
|
use convert_case::{Case, Casing};
|
|
use convert_case::{Case, Casing};
|
|
|
|
|
|
-fn parse_microrm_ref(attrs: &Vec<syn::Attribute>) -> proc_macro2::TokenStream {
|
|
|
|
|
|
+fn parse_microrm_ref(attrs: &[syn::Attribute]) -> proc_macro2::TokenStream {
|
|
for attr in attrs {
|
|
for attr in attrs {
|
|
- if attr.path.segments.len() == 0 {
|
|
|
|
|
|
+ if attr.path.segments.is_empty() {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- if attr.tokens.is_empty() {
|
|
|
|
- if attr.path.segments.last().unwrap().ident == "microrm_internal" {
|
|
|
|
- return quote! { crate }.into();
|
|
|
|
- }
|
|
|
|
|
|
+ if attr.tokens.is_empty() && attr.path.segments.last().unwrap().ident == "microrm_internal"
|
|
|
|
+ {
|
|
|
|
+ return quote! { crate };
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -40,7 +39,7 @@ fn parse_microrm_ref(attrs: &Vec<syn::Attribute>) -> proc_macro2::TokenStream {
|
|
pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(tokens as DeriveInput);
|
|
let input = parse_macro_input!(tokens as DeriveInput);
|
|
|
|
|
|
- let mut microrm_ref = parse_microrm_ref(&input.attrs);
|
|
|
|
|
|
+ let microrm_ref = parse_microrm_ref(&input.attrs);
|
|
|
|
|
|
let struct_name = &input.ident;
|
|
let struct_name = &input.ident;
|
|
let enum_name = format_ident!("{}Columns", &input.ident);
|
|
let enum_name = format_ident!("{}Columns", &input.ident);
|
|
@@ -70,14 +69,14 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
|
|
|
|
let field_name = name.ident.as_ref().unwrap().clone();
|
|
let field_name = name.ident.as_ref().unwrap().clone();
|
|
let field_name_str = format!("{}", field_name);
|
|
let field_name_str = format!("{}", field_name);
|
|
- field_names.push(quote! { Self::Column::#converted_case => #field_name_str }.into());
|
|
|
|
|
|
+ field_names.push(quote! { Self::Column::#converted_case => #field_name_str });
|
|
|
|
|
|
value_references.push(quote! { &self. #field_name });
|
|
value_references.push(quote! { &self. #field_name });
|
|
}
|
|
}
|
|
|
|
|
|
let field_count = fields.named.iter().count();
|
|
let field_count = fields.named.iter().count();
|
|
|
|
|
|
- let ret = quote!{
|
|
|
|
|
|
+ quote!{
|
|
// Related types for #struct_name
|
|
// Related types for #struct_name
|
|
#[derive(Clone,Copy)]
|
|
#[derive(Clone,Copy)]
|
|
#[allow(unused)]
|
|
#[allow(unused)]
|
|
@@ -127,9 +126,7 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
vec![ #value_references ]
|
|
vec![ #value_references ]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }.into();
|
|
|
|
-
|
|
|
|
- ret
|
|
|
|
|
|
+ }.into()
|
|
}
|
|
}
|
|
|
|
|
|
/// Marks a struct as able to be directly used in an Entity to correspond to a single database column.
|
|
/// Marks a struct as able to be directly used in an Entity to correspond to a single database column.
|
|
@@ -137,7 +134,7 @@ pub fn derive_entity(tokens: TokenStream) -> TokenStream {
|
|
pub fn derive_modelable(tokens: TokenStream) -> TokenStream {
|
|
pub fn derive_modelable(tokens: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(tokens as DeriveInput);
|
|
let input = parse_macro_input!(tokens as DeriveInput);
|
|
|
|
|
|
- let mut microrm_ref = parse_microrm_ref(&input.attrs);
|
|
|
|
|
|
+ let microrm_ref = parse_microrm_ref(&input.attrs);
|
|
|
|
|
|
let ident = input.ident;
|
|
let ident = input.ident;
|
|
|
|
|