pub(super) fn expand_any<T>(
        &self,
        ident: T,
        name: &TokenStream,
        installers: &TokenStream,
        tokens: &Tokens,
        generics: &syn::Generics,
    ) -> Result<TokenStream, Vec<syn::Error>>
    where
        T: Copy + ToTokens,
    {
        let Tokens {
            any,
            context_error,
            hash,
            module,
            named,
            pointer_guard,
            raw_into_mut,
            raw_into_ref,
            raw_str,
            shared,
            type_info,
            type_of,
            unsafe_from_value,
            unsafe_to_value,
            value,
            vm_error,
            install_with,
            ..
        } = &tokens;

        let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

        let generic_names = generics.type_params().map(|v| &v.ident).collect::<Vec<_>>();

        let impl_named = if !generic_names.is_empty() {
            quote! {
                impl #impl_generics #named for #ident #ty_generics #where_clause {
                    const BASE_NAME: #raw_str  = #raw_str::from_str(#name);

                    fn full_name() -> String {
                        [#name, "<", &#(#generic_names::full_name(),)* ">"].join("")
                    }
                }
            }
        } else {
            quote! {
                impl #impl_generics #named for #ident #ty_generics #where_clause {
                    const BASE_NAME: #raw_str = #raw_str::from_str(#name);
                }
            }
        };
        Ok(quote! {
            impl #impl_generics #any for #ident #ty_generics #where_clause {
                fn type_hash() -> #hash {
                    // Safety: `Hash` asserts that it is layout compatible with `TypeId`.
                    // TODO: remove this once we can have transmute-like functionality in a const fn.
                    #hash::from_type_id(std::any::TypeId::of::<Self>())
                }
            }

            impl #impl_generics #install_with for #ident #ty_generics #where_clause {
                fn install_with(module: &mut #module) -> ::std::result::Result<(), #context_error> {
                    #installers
                }
            }

            #impl_named

            impl #impl_generics #type_of for #ident #ty_generics #where_clause {
                fn type_hash() -> #hash {
                    <Self as #any>::type_hash()
                }

                fn type_info() -> #type_info {
                    #type_info::Any(#raw_str::from_str(std::any::type_name::<Self>()))
                }
            }

            impl #impl_generics #unsafe_from_value for &#ident #ty_generics #where_clause {
                type Output = *const #ident #ty_generics;
                type Guard = #raw_into_ref;

                fn from_value(
                    value: #value,
                ) -> ::std::result::Result<(Self::Output, Self::Guard), #vm_error> {
                    value.into_any_ptr()
                }

                unsafe fn unsafe_coerce(output: Self::Output) -> Self {
                    &*output
                }
            }

            impl #impl_generics #unsafe_from_value for &mut #ident #ty_generics #where_clause {
                type Output = *mut #ident  #ty_generics;
                type Guard = #raw_into_mut;

                fn from_value(
                    value: #value,
                ) -> ::std::result::Result<(Self::Output, Self::Guard), #vm_error> {
                    value.into_any_mut()
                }

                unsafe fn unsafe_coerce(output: Self::Output) -> Self {
                    &mut *output
                }
            }

            impl #impl_generics #unsafe_to_value for &#ident #ty_generics #where_clause {
                type Guard = #pointer_guard;

                unsafe fn unsafe_to_value(self) -> ::std::result::Result<(#value, Self::Guard), #vm_error> {
                    let (shared, guard) = #shared::from_ref(self);
                    Ok((#value::from(shared), guard))
                }
            }

            impl #impl_generics #unsafe_to_value for &mut #ident #ty_generics #where_clause {
                type Guard = #pointer_guard;

                unsafe fn unsafe_to_value(self) -> ::std::result::Result<(#value, Self::Guard), #vm_error> {
                    let (shared, guard) = #shared::from_mut(self);
                    Ok((#value::from(shared), guard))
                }
            }
        })
    }
/// Expand the necessary implementation details for `Any`.
Expand the necessary implementation details for `Any`.
Expand the necessary implementation details for ` Any ` .
pub(super) fn expand_any<T>(
        &self,
        ident: T,
        name: &TokenStream,
        installers: &TokenStream,
        tokens: &Tokens,
        generics: &syn::Generics,
    ) -> Result<TokenStream, Vec<syn::Error>>
    where
        T: Copy + ToTokens,
    {
        let Tokens {
            any,
            context_error,
            hash,
            module,
            named,
            pointer_guard,
            raw_into_mut,
            raw_into_ref,
            raw_str,
            shared,
            type_info,
            type_of,
            unsafe_from_value,
            unsafe_to_value,
            value,
            vm_error,
            install_with,
            ..
        } = &tokens;
        let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
        let generic_names = generics.type_params().map(|v| &v.ident).collect::<Vec<_>>();
        let impl_named = if !generic_names.is_empty() {
            quote! {
                impl #impl_generics #named for #ident #ty_generics #where_clause {
                    const BASE_NAME: #raw_str  = #raw_str::from_str(#name);
                    fn full_name() -> String {
                        [#name, "<", &#(#generic_names::full_name(),)* ">"].join("")
                    }
                }
            }
        } else {
            quote! {
                impl #impl_generics #named for #ident #ty_generics #where_clause {
                    const BASE_NAME: #raw_str = #raw_str::from_str(#name);
                }
            }
        };
        Ok(quote! {
            impl #impl_generics #any for #ident #ty_generics #where_clause {
                fn type_hash() -> #hash {
                    // Safety: `Hash` asserts that it is layout compatible with `TypeId`.
                    // TODO: remove this once we can have transmute-like functionality in a const fn.
                    #hash::from_type_id(std::any::TypeId::of::<Self>())
                }
            }
            impl #impl_generics #install_with for #ident #ty_generics #where_clause {
                fn install_with(module: &mut #module) -> ::std::result::Result<(), #context_error> {
                    #installers
                }
            }
            #impl_named
            impl #impl_generics #type_of for #ident #ty_generics #where_clause {
                fn type_hash() -> #hash {
                    <Self as #any>::type_hash()
                }
                fn type_info() -> #type_info {
                    #type_info::Any(#raw_str::from_str(std::any::type_name::<Self>()))
                }
            }
            impl #impl_generics #unsafe_from_value for &#ident #ty_generics #where_clause {
                type Output = *const #ident #ty_generics;
                type Guard = #raw_into_ref;
                fn from_value(
                    value: #value,
                ) -> ::std::result::Result<(Self::Output, Self::Guard), #vm_error> {
                    value.into_any_ptr()
                }
                unsafe fn unsafe_coerce(output: Self::Output) -> Self {
                    &*output
                }
            }
            impl #impl_generics #unsafe_from_value for &mut #ident #ty_generics #where_clause {
                type Output = *mut #ident  #ty_generics;
                type Guard = #raw_into_mut;
                fn from_value(
                    value: #value,
                ) -> ::std::result::Result<(Self::Output, Self::Guard), #vm_error> {
                    value.into_any_mut()
                }
                unsafe fn unsafe_coerce(output: Self::Output) -> Self {
                    &mut *output
                }
            }
            impl #impl_generics #unsafe_to_value for &#ident #ty_generics #where_clause {
                type Guard = #pointer_guard;
                unsafe fn unsafe_to_value(self) -> ::std::result::Result<(#value, Self::Guard), #vm_error> {
                    let (shared, guard) = #shared::from_ref(self);
                    Ok((#value::from(shared), guard))
                }
            }
            impl #impl_generics #unsafe_to_value for &mut #ident #ty_generics #where_clause {
                type Guard = #pointer_guard;
                unsafe fn unsafe_to_value(self) -> ::std::result::Result<(#value, Self::Guard), #vm_error> {
                    let (shared, guard) = #shared::from_mut(self);
                    Ok((#value::from(shared), guard))
                }
            }
        })
    }
pub ( super ) fn expand_any < T > ( & self , ident : T , name : & TokenStream , installers : & TokenStream , tokens : & Tokens , generics : & syn :: Generics , ) -> Result < TokenStream , Vec < syn :: Error > > where T : Copy + ToTokens , { let Tokens { any , context_error , hash , module , named , pointer_guard , raw_into_mut , raw_into_ref , raw_str , shared , type_info , type_of , unsafe_from_value , unsafe_to_value , value , vm_error , install_with , .. } = & tokens ; let ( impl_generics , ty_generics , where_clause ) = generics . split_for_impl ( ) ; let generic_names = generics . type_params ( ) . map ( | v | & v . ident ) . collect :: < Vec < _ > > ( ) ; let impl_named = if ! generic_names . is_empty ( ) { quote ! { impl impl_generics named for ident ty_generics where_clause { const BASE_NAME raw_str raw_str from_str ( name ) fn full_name ( ) String { [ name " " ( generic_names full_name ( ) ) " " ] join ( " " ) } } } } else { quote ! { impl impl_generics named for ident ty_generics where_clause { const BASE_NAME raw_str raw_str from_str ( name ) } } } ; Ok ( quote ! { impl impl_generics any for ident ty_generics where_clause { fn type_hash ( ) hash { // Safety: `Hash` asserts that it is layout compatible with `TypeId`. // TODO: remove this once we can have transmute-like functionality in a const fn. hash from_type_id ( std any TypeId of Self ( ) ) } } impl impl_generics install_with for ident ty_generics where_clause { fn install_with ( module mut module ) std result Result ( ) context_error { installers } } impl_named impl impl_generics type_of for ident ty_generics where_clause { fn type_hash ( ) hash { Self as any type_hash ( ) } fn type_info ( ) type_info { type_info Any ( raw_str from_str ( std any type_name Self ( ) ) ) } } impl impl_generics unsafe_from_value for ident ty_generics where_clause { type Output const ident ty_generics type Guard raw_into_ref fn from_value ( value value ) std result Result ( Self Output Self Guard ) vm_error { value into_any_ptr ( ) } unsafe fn unsafe_coerce ( output Self Output ) Self { output } } impl impl_generics unsafe_from_value for mut ident ty_generics where_clause { type Output mut ident ty_generics type Guard raw_into_mut fn from_value ( value value ) std result Result ( Self Output Self Guard ) vm_error { value into_any_mut ( ) } unsafe fn unsafe_coerce ( output Self Output ) Self { mut output } } impl impl_generics unsafe_to_value for ident ty_generics where_clause { type Guard pointer_guard unsafe fn unsafe_to_value ( self ) std result Result ( value Self Guard ) vm_error { let ( shared guard ) shared from_ref ( self ) Ok ( ( value from ( shared ) guard ) ) } } impl impl_generics unsafe_to_value for mut ident ty_generics where_clause { type Guard pointer_guard unsafe fn unsafe_to_value ( self ) std result Result ( value Self Guard ) vm_error { let ( shared guard ) shared from_mut ( self ) Ok ( ( value from ( shared ) guard ) ) } } } ) }
Expand the necessary implementation details for `Any`.
Expand the necessary implementation details for ` Any ` .
&self
ident
T
name
&TokenStream
installers
&TokenStream
tokens
&Tokens
generics
&syn::Generics
&self
ident
T
name
&TokenStream
installers
&TokenStream
tokens
&Tokens
generics
&syn::Generics