/// Iterates over each child of the given item.
Iterates over each child of the given item.
Iterates over each child of the given item .
pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F)
        where F: FnMut(def::Export)
    {
        if let Some(ref proc_macros) = self.proc_macros {
            if id == CRATE_DEF_INDEX {
                for (id, &(name, ref ext)) in proc_macros.iter().enumerate() {
                    let def = Def::Macro(
                        DefId {
                            krate: self.cnum,
                            index: DefIndex::new(id + 1)
                        },
                        ext.kind()
                    );
                    callback(def::Export { name: name, def: def, span: DUMMY_SP });
                }
            }
            return
        }
        // Find the item.
        let item = match self.maybe_entry(id) {
            None => return,
            Some(item) => item.decode(self),
        };
        // Iterate over all children.
        let macros_only = self.dep_kind.get().macros_only();
        for child_index in item.children.decode(self) {
            if macros_only {
                continue
            }
            // Get the item.
            if let Some(child) = self.maybe_entry(child_index) {
                let child = child.decode(self);
                match child.kind {
                    EntryKind::MacroDef(..) => {}
                    _ if macros_only => continue,
                    _ => {}
                }
                // Hand off the item to the callback.
                match child.kind {
                    // FIXME(eddyb) Don't encode these in children.
                    EntryKind::ForeignMod => {
                        for child_index in child.children.decode(self) {
                            if let Some(def) = self.get_def(child_index) {
                                callback(def::Export {
                                    def: def,
                                    name: self.item_name(child_index),
                                    span: self.entry(child_index).span.decode(self),
                                });
                            }
                        }
                        continue;
                    }
                    EntryKind::Impl(_) |
                    EntryKind::DefaultImpl(_) => continue,
                    _ => {}
                }
                let def_key = self.def_key(child_index);
                let span = child.span.decode(self);
                if let (Some(def), Some(name)) =
                    (self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) {
                    callback(def::Export { def: def, name: name, span: span });
                    // For non-reexport structs and variants add their constructors to children.
                    // Reexport lists automatically contain constructors when necessary.
                    match def {
                        Def::Struct(..) => {
                            if let Some(ctor_def_id) = self.get_struct_ctor_def_id(child_index) {
                                let ctor_kind = self.get_ctor_kind(child_index);
                                let ctor_def = Def::StructCtor(ctor_def_id, ctor_kind);
                                callback(def::Export { def: ctor_def, name: name, span: span });
                            }
                        }
                        Def::Variant(def_id) => {
                            // Braced variants, unlike structs, generate unusable names in
                            // value namespace, they are reserved for possible future use.
                            let ctor_kind = self.get_ctor_kind(child_index);
                            let ctor_def = Def::VariantCtor(def_id, ctor_kind);
                            callback(def::Export { def: ctor_def, name: name, span: span });
                        }
                        _ => {}
                    }
                }
            }
        }
        if let EntryKind::Mod(data) = item.kind {
            for exp in data.decode(self).reexports.decode(self) {
                match exp.def {
                    Def::Macro(..) => {}
                    _ if macros_only => continue,
                    _ => {}
                }
                callback(exp);
            }
        }
    }
pub fn each_child_of_item < F > ( & self , id : DefIndex , mut callback : F ) where F : FnMut ( def :: Export ) { if let Some ( ref proc_macros ) = self . proc_macros { if id == CRATE_DEF_INDEX { for ( id , & ( name , ref ext ) ) in proc_macros . iter ( ) . enumerate ( ) { let def = Def :: Macro ( DefId { krate : self . cnum , index : DefIndex :: new ( id + 1 ) } , ext . kind ( ) ) ; callback ( def :: Export { name : name , def : def , span : DUMMY_SP } ) ; } } return } // Find the item. let item = match self . maybe_entry ( id ) { None => return , Some ( item ) => item . decode ( self ) , } ; // Iterate over all children. let macros_only = self . dep_kind . get ( ) . macros_only ( ) ; for child_index in item . children . decode ( self ) { if macros_only { continue } // Get the item. if let Some ( child ) = self . maybe_entry ( child_index ) { let child = child . decode ( self ) ; match child . kind { EntryKind :: MacroDef ( .. ) => { } _ if macros_only => continue , _ => { } } // Hand off the item to the callback. match child . kind { // FIXME(eddyb) Don't encode these in children. EntryKind :: ForeignMod => { for child_index in child . children . decode ( self ) { if let Some ( def ) = self . get_def ( child_index ) { callback ( def :: Export { def : def , name : self . item_name ( child_index ) , span : self . entry ( child_index ) . span . decode ( self ) , } ) ; } } continue ; } EntryKind :: Impl ( _ ) | EntryKind :: DefaultImpl ( _ ) => continue , _ => { } } let def_key = self . def_key ( child_index ) ; let span = child . span . decode ( self ) ; if let ( Some ( def ) , Some ( name ) ) = ( self . get_def ( child_index ) , def_key . disambiguated_data . data . get_opt_name ( ) ) { callback ( def :: Export { def : def , name : name , span : span } ) ; // For non-reexport structs and variants add their constructors to children. // Reexport lists automatically contain constructors when necessary. match def { Def :: Struct ( .. ) => { if let Some ( ctor_def_id ) = self . get_struct_ctor_def_id ( child_index ) { let ctor_kind = self . get_ctor_kind ( child_index ) ; let ctor_def = Def :: StructCtor ( ctor_def_id , ctor_kind ) ; callback ( def :: Export { def : ctor_def , name : name , span : span } ) ; } } Def :: Variant ( def_id ) => { // Braced variants, unlike structs, generate unusable names in // value namespace, they are reserved for possible future use. let ctor_kind = self . get_ctor_kind ( child_index ) ; let ctor_def = Def :: VariantCtor ( def_id , ctor_kind ) ; callback ( def :: Export { def : ctor_def , name : name , span : span } ) ; } _ => { } } } } } if let EntryKind :: Mod ( data ) = item . kind { for exp in data . decode ( self ) . reexports . decode ( self ) { match exp . def { Def :: Macro ( .. ) => { } _ if macros_only => continue , _ => { } } callback ( exp ) ; } } }
Iterates over each child of the given item.
Iterates over each child of the given item .
&self
id
DefIndex
callback
F