pub(crate) fn find_providers(crate_name: &str, ast: &syn::File) -> Vec<ProviderSpecification> {
    //Construct an implementation of the `syn` crate's `Visit` trait which will examine all trait
    //declarations in the file looking for possible providers
    struct Visitor<'a> {
        crate_name: &'a str,
        providers: Vec<ProviderSpecification>,
    }

    impl<'ast> Visit<'ast> for Visitor<'ast> {
        fn visit_item_trait(&mut self, i: &'ast ItemTrait) {
            //First pass through to the default impl
            syn::visit::visit_item_trait(self, i);

            fn is_tracer_attribute(attr: &syn::Attribute) -> bool {
                match attr.path.segments.iter().last() {
                    Some(syn::PathSegment { ident, .. }) if *ident == "tracer" => true,
                    _ => false,
                }
            }

            //Check for the `tracer` or `tracers::tracer` attribute, splitting it out from the rest
            //of the attributes if present to ensure the
            //hash matches the same hash computed by the proc macro when it's invoked on this
            //trait during the compile stage
            let mut i = i.clone();
            let (mut tracer_attrs, other_attrs) = i
                .attrs
                .into_iter()
                .partition::<Vec<syn::Attribute>, _>(is_tracer_attribute);
            if let Some(tracer_attr) = tracer_attrs.pop() {
                //This looks like a provider trait.
                //Normally there should be only one `#[tracer]` but that's for the full compiler to
                //sort out.  We'll just assume the first one is the one we want
                i.attrs = other_attrs;
                if let Ok(provider) = ProviderSpecification::from_trait(
                    self.crate_name,
                    TracerAttribute::from_attribute(tracer_attr)
                        .expect("Failed parsing attribute metadata"),
                    i,
                ) {
                    self.providers.push(provider)
                }
            }
        }
    }

    let mut visitor = Visitor {
        crate_name,
        providers: Vec::new(),
    };
    visitor.visit_file(ast);

    visitor.providers
}
/// Scans the AST of a Rust source file, finding all traits marked with the `tracer` attribute,
/// parses the contents of the trait, and deduces the provider spec from that.
///
/// Note that if any traits are encountered with the `tracer` attribute but which are in some way
/// invalid as providers, those traits will be silently ignored.  At compile time the `tracer`
/// attribute will cause a very detailed compile error so there's no chance the user will miss this
/// mistake.
Scans the AST of a Rust source file, finding all traits marked with the `tracer` attribute,
parses the contents of the trait, and deduces the provider spec from that.

Note that if any traits are encountered with the `tracer` attribute but which are in some way
invalid as providers, those traits will be silently ignored.  At compile time the `tracer`
attribute will cause a very detailed compile error so there's no chance the user will miss this
mistake.
Scans the AST of a Rust source file finding all traits marked with the ` tracer ` attribute parses the contents of the trait and deduces the provider spec from that . Note that if any traits are encountered with the ` tracer ` attribute but which are in some way invalid as providers those traits will be silently ignored . At compile time the ` tracer ` attribute will cause a very detailed compile error so there ' s no chance the user will miss this mistake .
pub(crate) fn find_providers(crate_name: &str, ast: &syn::File) -> Vec<ProviderSpecification> {
    //Construct an implementation of the `syn` crate's `Visit` trait which will examine all trait
    //declarations in the file looking for possible providers
    struct Visitor<'a> {
        crate_name: &'a str,
        providers: Vec<ProviderSpecification>,
    }
    impl<'ast> Visit<'ast> for Visitor<'ast> {
        fn visit_item_trait(&mut self, i: &'ast ItemTrait) {
            //First pass through to the default impl
            syn::visit::visit_item_trait(self, i);
            fn is_tracer_attribute(attr: &syn::Attribute) -> bool {
                match attr.path.segments.iter().last() {
                    Some(syn::PathSegment { ident, .. }) if *ident == "tracer" => true,
                    _ => false,
                }
            }
            //Check for the `tracer` or `tracers::tracer` attribute, splitting it out from the rest
            //of the attributes if present to ensure the
            //hash matches the same hash computed by the proc macro when it's invoked on this
            //trait during the compile stage
            let mut i = i.clone();
            let (mut tracer_attrs, other_attrs) = i
                .attrs
                .into_iter()
                .partition::<Vec<syn::Attribute>, _>(is_tracer_attribute);
            if let Some(tracer_attr) = tracer_attrs.pop() {
                //This looks like a provider trait.
                //Normally there should be only one `#[tracer]` but that's for the full compiler to
                //sort out.  We'll just assume the first one is the one we want
                i.attrs = other_attrs;
                if let Ok(provider) = ProviderSpecification::from_trait(
                    self.crate_name,
                    TracerAttribute::from_attribute(tracer_attr)
                        .expect("Failed parsing attribute metadata"),
                    i,
                ) {
                    self.providers.push(provider)
                }
            }
        }
    }
    let mut visitor = Visitor {
        crate_name,
        providers: Vec::new(),
    };
    visitor.visit_file(ast);
    visitor.providers
}
pub ( crate ) fn find_providers ( crate_name : & str , ast : & syn :: File ) -> Vec < ProviderSpecification > { //Construct an implementation of the `syn` crate's `Visit` trait which will examine all trait //declarations in the file looking for possible providers struct Visitor < ' a > { crate_name : & ' a str , providers : Vec < ProviderSpecification > , } impl < ' ast > Visit < ' ast > for Visitor < ' ast > { fn visit_item_trait ( & mut self , i : & ' ast ItemTrait ) { //First pass through to the default impl syn :: visit :: visit_item_trait ( self , i ) ; fn is_tracer_attribute ( attr : & syn :: Attribute ) -> bool { match attr . path . segments . iter ( ) . last ( ) { Some ( syn :: PathSegment { ident , .. } ) if * ident == " " => true , _ => false , } } //Check for the `tracer` or `tracers::tracer` attribute, splitting it out from the rest //of the attributes if present to ensure the //hash matches the same hash computed by the proc macro when it's invoked on this //trait during the compile stage let mut i = i . clone ( ) ; let ( mut tracer_attrs , other_attrs ) = i . attrs . into_iter ( ) . partition :: < Vec < syn :: Attribute > , _ > ( is_tracer_attribute ) ; if let Some ( tracer_attr ) = tracer_attrs . pop ( ) { //This looks like a provider trait. //Normally there should be only one `#[tracer]` but that's for the full compiler to //sort out.  We'll just assume the first one is the one we want i . attrs = other_attrs ; if let Ok ( provider ) = ProviderSpecification :: from_trait ( self . crate_name , TracerAttribute :: from_attribute ( tracer_attr ) . expect ( " " ) , i , ) { self . providers . push ( provider ) } } } } let mut visitor = Visitor { crate_name , providers : Vec :: new ( ) , } ; visitor . visit_file ( ast ) ; visitor . providers }
Scans the AST of a Rust source file, finding all traits marked with the `tracer` attribute,
parses the contents of the trait, and deduces the provider spec from that.
Scans the AST of a Rust source file finding all traits marked with the ` tracer ` attribute parses the contents of the trait and deduces the provider spec from that .
crate_name
&str
ast
&syn::File
crate_name
&str
ast
&syn::File