fn generate_impl_mod(&self) -> TokenStream {
        let mod_name = self.get_provider_impl_mod_name();
        let struct_type_name = self.get_provider_impl_struct_type_name();
        let struct_var_name = self.get_provider_impl_struct_var_name();
        let struct_type_params = self.generate_provider_struct_type_params();
        let instance_var_name = self.get_provider_instance_var_name();
        let define_provider_call = self.generate_define_provider_call();
        let provider_var_name = syn::Ident::new("p", self.spec.item_trait().span());
        let struct_members: Vec<_> = self
            .probes
            .iter()
            .map(ProbeGenerator::generate_struct_member_declaration)
            .collect();

        let struct_initializers: Vec<_> = self
            .probes
            .iter()
            .map(|probe| probe.generate_struct_member_initialization(&provider_var_name))
            .collect();

        let span = self.spec.item_trait().span();
        quote_spanned! {span=>
            mod #mod_name {
                use ::tracers::runtime::failure::{format_err, Fallible};
                use ::tracers::runtime::dynamic::once_cell::sync::OnceCell;
                use ::tracers::runtime::dynamic::{SystemTracer,SystemProvider,ProviderBuilder,Tracer};

                // Need the `Provider` trait in scope so we can access its methods on its
                // implementors
                use ::tracers::runtime::dynamic::Provider as _;
                use ::core::result::Result;

                #[allow(dead_code)]
                pub(super) struct #struct_type_name<#struct_type_params> {
                    #(pub #struct_members),*
                }

                unsafe impl<#struct_type_params> Send for #struct_type_name<#struct_type_params> {}
                unsafe impl<#struct_type_params> Sync for #struct_type_name <#struct_type_params>{}

                static #instance_var_name: OnceCell<Fallible<SystemProvider>> = OnceCell::new();
                static #struct_var_name: OnceCell<Result<#struct_type_name, String>> = OnceCell::new();
                static IMPL_OPT: OnceCell<Result<&'static #struct_type_name, &'static str>> = OnceCell::new();

                impl<#struct_type_params> #struct_type_name<#struct_type_params> {
                   #[allow(dead_code)]
                   pub(super) fn get() -> Result<&'static #struct_type_name<#struct_type_params>, &'static str> {
                       //let imp: &'static Result<&'static #struct_type_name, &'static str> = IMPL_OPT.get_or_init(|| {
                       let imp: &'static Result<_,_> = IMPL_OPT.get_or_init(|| {
                           // The reason for this seemingly-excessive nesting is that it's possible for
                           // both the creation of `SystemProvider` or the subsequent initialization of
                           // #struct_type_name to fail with different and also relevant errors.  By
                           // separting them this way we're able to preserve the details about any init
                           // failures that happen, while at runtime when firing probes it's a simple
                           // call of a method on an `Option<T>`.  I don't have any data to back this
                           // up but I suspect that allows for better optimizations, since we know an
                           // `Option<&T>` is implemented as a simple pointer where `None` is `NULL`.
                           let imp: &Result<#struct_type_name<#struct_type_params>, String> = #struct_var_name.get_or_init(|| {
                               // Initialzie the `SystemProvider`, capturing any initialization errors
                               let #provider_var_name: &Fallible<SystemProvider> = #instance_var_name.get_or_init(|| {
                                    #define_provider_call
                               });

                               // Transform this #provider_var_name into an owned `Fallible` containing
                               // references to `T` or `E`, since there's not much useful you can do
                               // with just a `&Result`.
                               match #provider_var_name.as_ref() {
                                   Err(e) => Err(format!("Provider initialization failed: {}", e)),
                                   Ok(#provider_var_name) => {
                                       // Proceed to create the struct containing each of the probes'
                                       // `ProviderProbe` instances
                                       Ok(
                                           #struct_type_name{
                                               #(#struct_initializers,)*
                                           }
                                       )
                                   }
                               }
                           });

                           //Convert this &Fallible<..> into an Result<&T, &'static str>
                           imp.as_ref().map_err(|e| e.as_ref())
                       });

                       //Copy this `&Result<&T, &String>` to a new `Result<&T, &str>`.  Since that should be
                       //implemented as just a pointer, this should be effectively free
                       //*imp
                       imp.map_err(|e| e.as_ref())
                   }
                }
            }
        }
    }
/// The implementation of the probing logic is complex enough that it involves the declaration of a
/// few variables and one new struct type.  All of this is contained within a module, to avoid the
/// possibility of collissions with other code.  This method generates that module and all its
/// contents.
///
/// The contents are, briefly:
/// * The module itself, named after the trait
/// * A declaration of a `struct` which will hold references to all of the probes
/// * Multiple static `OnceCell` variables which hold the underlying provider instance as well as
/// the instance of the `struct` which holds references to all of the probes
The implementation of the probing logic is complex enough that it involves the declaration of a
few variables and one new struct type.  All of this is contained within a module, to avoid the
possibility of collissions with other code.  This method generates that module and all its
contents.


The implementation of the probing logic is complex enough that it involves the declaration of a few variables and one new struct type . All of this is contained within a module to avoid the possibility of collissions with other code . This method generates that module and all its contents .
fn generate_impl_mod(&self) -> TokenStream {
        let mod_name = self.get_provider_impl_mod_name();
        let struct_type_name = self.get_provider_impl_struct_type_name();
        let struct_var_name = self.get_provider_impl_struct_var_name();
        let struct_type_params = self.generate_provider_struct_type_params();
        let instance_var_name = self.get_provider_instance_var_name();
        let define_provider_call = self.generate_define_provider_call();
        let provider_var_name = syn::Ident::new("p", self.spec.item_trait().span());
        let struct_members: Vec<_> = self
            .probes
            .iter()
            .map(ProbeGenerator::generate_struct_member_declaration)
            .collect();
        let struct_initializers: Vec<_> = self
            .probes
            .iter()
            .map(|probe| probe.generate_struct_member_initialization(&provider_var_name))
            .collect();
        let span = self.spec.item_trait().span();
        quote_spanned! {span=>
            mod #mod_name {
                use ::tracers::runtime::failure::{format_err, Fallible};
                use ::tracers::runtime::dynamic::once_cell::sync::OnceCell;
                use ::tracers::runtime::dynamic::{SystemTracer,SystemProvider,ProviderBuilder,Tracer};
                // Need the `Provider` trait in scope so we can access its methods on its
                // implementors
                use ::tracers::runtime::dynamic::Provider as _;
                use ::core::result::Result;
                #[allow(dead_code)]
                pub(super) struct #struct_type_name<#struct_type_params> {
                    #(pub #struct_members),*
                }
                unsafe impl<#struct_type_params> Send for #struct_type_name<#struct_type_params> {}
                unsafe impl<#struct_type_params> Sync for #struct_type_name <#struct_type_params>{}
                static #instance_var_name: OnceCell<Fallible<SystemProvider>> = OnceCell::new();
                static #struct_var_name: OnceCell<Result<#struct_type_name, String>> = OnceCell::new();
                static IMPL_OPT: OnceCell<Result<&'static #struct_type_name, &'static str>> = OnceCell::new();
                impl<#struct_type_params> #struct_type_name<#struct_type_params> {
                   #[allow(dead_code)]
                   pub(super) fn get() -> Result<&'static #struct_type_name<#struct_type_params>, &'static str> {
                       //let imp: &'static Result<&'static #struct_type_name, &'static str> = IMPL_OPT.get_or_init(|| {
                       let imp: &'static Result<_,_> = IMPL_OPT.get_or_init(|| {
                           // The reason for this seemingly-excessive nesting is that it's possible for
                           // both the creation of `SystemProvider` or the subsequent initialization of
                           // #struct_type_name to fail with different and also relevant errors.  By
                           // separting them this way we're able to preserve the details about any init
                           // failures that happen, while at runtime when firing probes it's a simple
                           // call of a method on an `Option<T>`.  I don't have any data to back this
                           // up but I suspect that allows for better optimizations, since we know an
                           // `Option<&T>` is implemented as a simple pointer where `None` is `NULL`.
                           let imp: &Result<#struct_type_name<#struct_type_params>, String> = #struct_var_name.get_or_init(|| {
                               // Initialzie the `SystemProvider`, capturing any initialization errors
                               let #provider_var_name: &Fallible<SystemProvider> = #instance_var_name.get_or_init(|| {
                                    #define_provider_call
                               });
                               // Transform this #provider_var_name into an owned `Fallible` containing
                               // references to `T` or `E`, since there's not much useful you can do
                               // with just a `&Result`.
                               match #provider_var_name.as_ref() {
                                   Err(e) => Err(format!("Provider initialization failed: {}", e)),
                                   Ok(#provider_var_name) => {
                                       // Proceed to create the struct containing each of the probes'
                                       // `ProviderProbe` instances
                                       Ok(
                                           #struct_type_name{
                                               #(#struct_initializers,)*
                                           }
                                       )
                                   }
                               }
                           });
                           //Convert this &Fallible<..> into an Result<&T, &'static str>
                           imp.as_ref().map_err(|e| e.as_ref())
                       });
                       //Copy this `&Result<&T, &String>` to a new `Result<&T, &str>`.  Since that should be
                       //implemented as just a pointer, this should be effectively free
                       //*imp
                       imp.map_err(|e| e.as_ref())
                   }
                }
            }
        }
    }
fn generate_impl_mod ( & self ) -> TokenStream { let mod_name = self . get_provider_impl_mod_name ( ) ; let struct_type_name = self . get_provider_impl_struct_type_name ( ) ; let struct_var_name = self . get_provider_impl_struct_var_name ( ) ; let struct_type_params = self . generate_provider_struct_type_params ( ) ; let instance_var_name = self . get_provider_instance_var_name ( ) ; let define_provider_call = self . generate_define_provider_call ( ) ; let provider_var_name = syn :: Ident :: new ( " " , self . spec . item_trait ( ) . span ( ) ) ; let struct_members : Vec < _ > = self . probes . iter ( ) . map ( ProbeGenerator :: generate_struct_member_declaration ) . collect ( ) ; let struct_initializers : Vec < _ > = self . probes . iter ( ) . map ( | probe | probe . generate_struct_member_initialization ( & provider_var_name ) ) . collect ( ) ; let span = self . spec . item_trait ( ) . span ( ) ; quote_spanned ! { span mod mod_name { use tracers runtime failure { format_err Fallible } use tracers runtime dynamic once_cell sync OnceCell use tracers runtime dynamic { SystemTracer SystemProvider ProviderBuilder Tracer } // Need the `Provider` trait in scope so we can access its methods on its // implementors use tracers runtime dynamic Provider as use core result Result [ allow ( dead_code ) ] pub ( super ) struct struct_type_name struct_type_params { ( pub struct_members ) } unsafe impl struct_type_params Send for struct_type_name struct_type_params { } unsafe impl struct_type_params Sync for struct_type_name struct_type_params { } static instance_var_name OnceCell Fallible SystemProvider OnceCell new ( ) static struct_var_name OnceCell Result struct_type_name String OnceCell new ( ) static IMPL_OPT OnceCell Result ' static struct_type_name ' static str OnceCell new ( ) impl struct_type_params struct_type_name struct_type_params { [ allow ( dead_code ) ] pub ( super ) fn get ( ) Result ' static struct_type_name struct_type_params ' static str { //let imp: &'static Result<&'static #struct_type_name, &'static str> = IMPL_OPT.get_or_init(|| { let imp ' static Result IMPL_OPT get_or_init ( { // The reason for this seemingly-excessive nesting is that it's possible for // both the creation of `SystemProvider` or the subsequent initialization of // #struct_type_name to fail with different and also relevant errors.  By // separting them this way we're able to preserve the details about any init // failures that happen, while at runtime when firing probes it's a simple // call of a method on an `Option<T>`.  I don't have any data to back this // up but I suspect that allows for better optimizations, since we know an // `Option<&T>` is implemented as a simple pointer where `None` is `NULL`. let imp Result struct_type_name struct_type_params String struct_var_name get_or_init ( { // Initialzie the `SystemProvider`, capturing any initialization errors let provider_var_name Fallible SystemProvider instance_var_name get_or_init ( { define_provider_call } ) // Transform this #provider_var_name into an owned `Fallible` containing // references to `T` or `E`, since there's not much useful you can do // with just a `&Result`. match provider_var_name as_ref ( ) { Err ( e ) Err ( format ( " " e ) ) Ok ( provider_var_name ) { // Proceed to create the struct containing each of the probes' // `ProviderProbe` instances Ok ( struct_type_name { ( struct_initializers ) } ) } } } ) //Convert this &Fallible<..> into an Result<&T, &'static str> imp as_ref ( ) map_err ( e e as_ref ( ) ) } ) //Copy this `&Result<&T, &String>` to a new `Result<&T, &str>`.  Since that should be //implemented as just a pointer, this should be effectively free //*imp imp map_err ( e e as_ref ( ) ) } } } } }
The implementation of the probing logic is complex enough that it involves the declaration of a
few variables and one new struct type.
The implementation of the probing logic is complex enough that it involves the declaration of a few variables and one new struct type .
&self
&self