diff --git a/build.rs b/build.rs index 9d35be07..1e3b695e 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,8 @@ -use convert_case::{Case, Casing}; use std::collections::HashSet; -use std::env; -use std::fs; use std::path::Path; +use std::{env, fs}; + +use convert_case::{Case, Casing}; // I hate to admit this, but a fair bit of this file was written by chatgpt to speed things up // and to allow me to continue to procrastinate about learning how to do i/o stuff in rust. diff --git a/enum-field-getter/src/lib.rs b/enum-field-getter/src/lib.rs index 637dc7e5..b5f6b9cc 100644 --- a/enum-field-getter/src/lib.rs +++ b/enum-field-getter/src/lib.rs @@ -1,12 +1,12 @@ #![doc = include_str!("../README.md")] +use std::collections::{HashMap, HashSet}; + use proc_macro::TokenStream; use proc_macro_error::{abort_call_site, emit_warning, proc_macro_error}; use quote::{format_ident, quote}; use syn::{parse_macro_input, Data, DeriveInput, Fields, Type}; -use std::collections::{HashMap, HashSet}; - /// See top-level crate documentation. #[proc_macro_error] #[proc_macro_derive(EnumFieldGetter)] @@ -25,29 +25,45 @@ pub fn enum_field_getter(stream: TokenStream) -> TokenStream { let ident = field.ident.clone().unwrap().to_string(); let field_ty = field.ty.clone(); let df = (field_ty.clone(), vec![variant.ident.to_string()]); - field_info.entry(ident.clone()).and_modify(|info| { - let (ty, used_variants) = info; - if quote!{#field_ty}.to_string() != quote!{#ty}.to_string() { - emit_warning!(field, "fields must be the same type across all variants - no getter will be emitted for this field"); - incompatible.insert(ident.clone()); - } else { - used_variants.push(variant.ident.to_string()); - } - }).or_insert(df); + field_info + .entry(ident.clone()) + .and_modify(|info| { + let (ty, used_variants) = info; + if quote! {#field_ty}.to_string() != quote! {#ty}.to_string() { + emit_warning!( + field, + "fields must be the same type across all variants - no getter \ + will be emitted for this field" + ); + incompatible.insert(ident.clone()); + } else { + used_variants.push(variant.ident.to_string()); + } + }) + .or_insert(df); } } else if let Fields::Unnamed(_) = variant.fields { for (i, field) in variant.fields.iter().enumerate() { let field_ty = field.ty.clone(); let df = (field_ty.clone(), vec![variant.ident.to_string()]); - tuple_field_info.entry(i).and_modify(|info| { - let (ty, used_variants) = info; - if quote!{#field_ty}.to_string() != quote!{#ty}.to_string() { - emit_warning!(field, "Fields must be the same type across all variants - no getter will be emitted for this field.\nExpected type {}, got {}.", quote!{#ty}.to_string(), quote!{#field_ty}.to_string()); - tuple_incompatible.insert(i); - } else { - used_variants.push(variant.ident.to_string()); - } - }).or_insert(df); + tuple_field_info + .entry(i) + .and_modify(|info| { + let (ty, used_variants) = info; + if quote! {#field_ty}.to_string() != quote! {#ty}.to_string() { + emit_warning!( + field, + "Fields must be the same type across all variants - no getter \ + will be emitted for this field.\nExpected type {}, got {}.", + quote! {#ty}.to_string(), + quote! {#field_ty}.to_string() + ); + tuple_incompatible.insert(i); + } else { + used_variants.push(variant.ident.to_string()); + } + }) + .or_insert(df); } } } diff --git a/playground/components/ProjectIdPlayer.vue b/playground/components/ProjectIdPlayer.vue index 66ba4504..20c866c7 100644 --- a/playground/components/ProjectIdPlayer.vue +++ b/playground/components/ProjectIdPlayer.vue @@ -7,7 +7,7 @@ :title="title" :instructions="instructions" :description="description" - :zip="null" + :zip="zip" >