1
0
mirror of https://github.com/danog/strum.git synced 2024-12-02 09:27:57 +01:00

renamed variables

This commit is contained in:
Peter Glotfelty 🚀 2020-07-27 15:47:29 +00:00
parent 80d654e274
commit 9ea7fc12c0
5 changed files with 18 additions and 19 deletions

View File

@ -11,16 +11,16 @@ pub fn enum_message_inner(ast: &syn::DeriveInput) -> TokenStream {
_ => panic!("EnumMessage only works on Enums"), _ => panic!("EnumMessage only works on Enums"),
}; };
let type_meta = ast.get_type_properties(); let type_properties = ast.get_type_properties();
let mut arms = Vec::new(); let mut arms = Vec::new();
let mut detailed_arms = Vec::new(); let mut detailed_arms = Vec::new();
let mut serializations = Vec::new(); let mut serializations = Vec::new();
for variant in variants { for variant in variants {
let meta = variant.get_variant_properties(); let variant_properties = variant.get_variant_properties();
let messages = meta.message.as_ref(); let messages = variant_properties.message.as_ref();
let detailed_messages = meta.detailed_message.as_ref(); let detailed_messages = variant_properties.detailed_message.as_ref();
let ident = &variant.ident; let ident = &variant.ident;
use syn::Fields::*; use syn::Fields::*;
@ -32,7 +32,7 @@ pub fn enum_message_inner(ast: &syn::DeriveInput) -> TokenStream {
// You can't disable getting the serializations. // You can't disable getting the serializations.
{ {
let serialization_variants = meta.get_serializations(type_meta.case_style); let serialization_variants = variant_properties.get_serializations(type_properties.case_style);
let count = serialization_variants.len(); let count = serialization_variants.len();
serializations.push(quote! { serializations.push(quote! {
@ -44,7 +44,7 @@ pub fn enum_message_inner(ast: &syn::DeriveInput) -> TokenStream {
} }
// But you can disable the messages. // But you can disable the messages.
if meta.is_disabled { if variant_properties.is_disabled {
continue; continue;
} }

View File

@ -14,12 +14,12 @@ pub fn enum_properties_inner(ast: &syn::DeriveInput) -> TokenStream {
let mut arms = Vec::new(); let mut arms = Vec::new();
for variant in variants { for variant in variants {
let ident = &variant.ident; let ident = &variant.ident;
let meta = variant.get_variant_properties(); let variant_properties = variant.get_variant_properties();
let mut string_arms = Vec::new(); let mut string_arms = Vec::new();
let mut bool_arms = Vec::new(); let mut bool_arms = Vec::new();
let mut num_arms = Vec::new(); let mut num_arms = Vec::new();
// But you can disable the messages. // But you can disable the messages.
if meta.is_disabled { if variant_properties.is_disabled {
continue; continue;
} }
@ -30,7 +30,7 @@ pub fn enum_properties_inner(ast: &syn::DeriveInput) -> TokenStream {
Named(..) => quote! { {..} }, Named(..) => quote! { {..} },
}; };
for (key, value) in meta.string_props { for (key, value) in variant_properties.string_props {
string_arms.push(quote! { #key => ::std::option::Option::Some( #value )}) string_arms.push(quote! { #key => ::std::option::Option::Some( #value )})
} }

View File

@ -14,11 +14,11 @@ pub fn enum_variant_names_inner(ast: &syn::DeriveInput) -> TokenStream {
}; };
// Derives for the generated enum // Derives for the generated enum
let type_meta = ast.get_type_properties(); let type_properties = ast.get_type_properties();
let names = variants let names = variants
.iter() .iter()
.map(|v| v.ident.convert_case(type_meta.case_style)) .map(|v| v.ident.convert_case(type_properties.case_style))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
quote! { quote! {

View File

@ -15,7 +15,6 @@ pub fn display_inner(ast: &syn::DeriveInput) -> TokenStream {
let mut arms = Vec::new(); let mut arms = Vec::new();
for variant in variants { for variant in variants {
use syn::Fields::*;
let ident = &variant.ident; let ident = &variant.ident;
let variant_properties = variant.get_variant_properties(); let variant_properties = variant.get_variant_properties();
@ -27,9 +26,9 @@ pub fn display_inner(ast: &syn::DeriveInput) -> TokenStream {
let output = variant_properties.get_preferred_name(type_properties.case_style); let output = variant_properties.get_preferred_name(type_properties.case_style);
let params = match variant.fields { let params = match variant.fields {
Unit => quote! {}, syn::Fields::Unit => quote! {},
Unnamed(..) => quote! { (..) }, syn::Fields::Unnamed(..) => quote! { (..) },
Named(..) => quote! { {..} }, syn::Fields::Named(..) => quote! { {..} },
}; };
arms.push(quote! { #name::#ident #params => f.pad(#output) }); arms.push(quote! { #name::#ident #params => f.pad(#output) });

View File

@ -11,19 +11,19 @@ pub fn to_string_inner(ast: &syn::DeriveInput) -> TokenStream {
_ => panic!("ToString only works on Enums"), _ => panic!("ToString only works on Enums"),
}; };
let type_meta = ast.get_type_properties(); let type_properties = ast.get_type_properties();
let mut arms = Vec::new(); let mut arms = Vec::new();
for variant in variants { for variant in variants {
use syn::Fields::*; use syn::Fields::*;
let ident = &variant.ident; let ident = &variant.ident;
let meta = variant.get_variant_properties(); let variant_properties = variant.get_variant_properties();
if meta.is_disabled { if variant_properties.is_disabled {
continue; continue;
} }
// Look at all the serialize attributes. // Look at all the serialize attributes.
let output = meta.get_preferred_name(type_meta.case_style); let output = variant_properties.get_preferred_name(type_properties.case_style);
let params = match variant.fields { let params = match variant.fields {
Unit => quote! {}, Unit => quote! {},