diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-22 20:21:41 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-22 20:21:41 +0800 |
| commit | d7c9ad94113cca2f782666e37a0aa4fb7b8d7d86 (patch) | |
| tree | 323dfc74a274463500ac52c7bb7b83029b771411 /mingling_macros/src/renderer.rs | |
| parent | 232f31c6649e6348a5b0b64362f185f7f4db1dc0 (diff) | |
Support qualified type paths in four macros
Diffstat (limited to 'mingling_macros/src/renderer.rs')
| -rw-r--r-- | mingling_macros/src/renderer.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/mingling_macros/src/renderer.rs b/mingling_macros/src/renderer.rs index ac82799..c4b2786 100644 --- a/mingling_macros/src/renderer.rs +++ b/mingling_macros/src/renderer.rs @@ -44,11 +44,6 @@ pub fn renderer_attr(attr: TokenStream, item: TokenStream) -> TokenStream { Err(e) => return e.to_compile_error().into(), }; - // Check that the previous type is a single-segment type (no `::`) - if let Some(err_tokens) = crate::check_single_segment_type(&previous_type, "#[renderer]") { - return err_tokens.into(); - } - // Validate return type – now returns Some(type) if custom type, None if () let return_type = extract_return_type(&input_fn.sig); @@ -174,23 +169,26 @@ pub fn build_renderer_entry( struct_name: &syn::Ident, previous_type: &TypePath, ) -> proc_macro2::TokenStream { + let enum_variant = &previous_type.path.segments.last().unwrap().ident; quote! { - #struct_name => #previous_type, + #struct_name => #enum_variant, } } /// Builds the renderer existence check entry pub fn build_renderer_exist_entry(previous_type: &TypePath) -> proc_macro2::TokenStream { + let enum_variant = &previous_type.path.segments.last().unwrap().ident; quote! { - Self::#previous_type => true, + Self::#enum_variant => true, } } /// Builds the general renderer entry #[cfg(feature = "general_renderer")] pub fn build_general_renderer_entry(previous_type: &TypePath) -> proc_macro2::TokenStream { + let enum_variant = &previous_type.path.segments.last().unwrap().ident; quote! { - Self::#previous_type => { + Self::#enum_variant => { // SAFETY: Only types that match will enter this branch for forced conversion, // and `AnyOutput::new` ensures the type implements serde::Serialize let raw = unsafe { any.restore::<#previous_type>().unwrap_unchecked() }; |
