diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-13 21:41:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-13 21:41:24 +0800 |
| commit | e730cea0224323c97539fcc657a83ee6320bcc1c (patch) | |
| tree | f05c9795fd19b345063835fa798a01e9b094b195 /mingling_macros | |
| parent | 17cf59fe8220ac5befbbe8333fa0515ab532103d (diff) | |
Add Pickable implementation for enums with EnumTag trait
Diffstat (limited to 'mingling_macros')
| -rw-r--r-- | mingling_macros/src/enum_tag.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/mingling_macros/src/enum_tag.rs b/mingling_macros/src/enum_tag.rs index a30a0d5..497bc88 100644 --- a/mingling_macros/src/enum_tag.rs +++ b/mingling_macros/src/enum_tag.rs @@ -70,10 +70,13 @@ fn derive_enum_tag_impl(input: DeriveInput) -> Result<proc_macro2::TokenStream> } } - fn build_enum(name: String) -> Self { + fn build_enum(name: String) -> Option<Self> + where + Self: Sized + { match name.as_str() { #(#build_match_arms)* - _ => panic!("Invalid enum variant name: {}", name), + _ => None, } } @@ -128,7 +131,7 @@ fn process_variant( }); build_match_arms.push(quote! { - #variant_name_str => #enum_name::#variant_name, + #variant_name_str => Some(#enum_name::#variant_name), }); Ok(()) |
