fn build_features(s: &Summary, method: &Method)
                  -> CargoResult<(HashMap<String, Vec<String>>, HashSet<String>)> {
    let mut deps = HashMap::new();
    let mut used = HashSet::new();
    let mut visited = HashSet::new();
    match *method {
        Method::Everything => {
            for key in s.features().keys() {
                try!(add_feature(s, key, &mut deps, &mut used, &mut visited));
            }
            for dep in s.dependencies().iter().filter(|d| d.is_optional()) {
                try!(add_feature(s, dep.name(), &mut deps, &mut used,
                                 &mut visited));
            }
        }
        Method::Required { features: requested_features, .. } =>  {
            for feat in requested_features.iter() {
                try!(add_feature(s, feat, &mut deps, &mut used, &mut visited));
            }
        }
    }
    match *method {
        Method::Everything |
        Method::Required { uses_default_features: true, .. } => {
            if s.features().get("default").is_some() {
                try!(add_feature(s, "default", &mut deps, &mut used,
                                 &mut visited));
            }
        }
        Method::Required { uses_default_features: false, .. } => {}
    }
    return Ok((deps, used));

    fn add_feature(s: &Summary, feat: &str,
                   deps: &mut HashMap<String, Vec<String>>,
                   used: &mut HashSet<String>,
                   visited: &mut HashSet<String>) -> CargoResult<()> {
        if feat.is_empty() { return Ok(()) }

        // If this feature is of the form `foo/bar`, then we just lookup package
        // `foo` and enable its feature `bar`. Otherwise this feature is of the
        // form `foo` and we need to recurse to enable the feature `foo` for our
        // own package, which may end up enabling more features or just enabling
        // a dependency.
        let mut parts = feat.splitn(2, '/');
        let feat_or_package = parts.next().unwrap();
        match parts.next() {
            Some(feat) => {
                let package = feat_or_package;
                used.insert(package.to_string());
                deps.entry(package.to_string())
                    .or_insert(Vec::new())
                    .push(feat.to_string());
            }
            None => {
                let feat = feat_or_package;
                if !visited.insert(feat.to_string()) {
                    bail!("Cyclic feature dependency: feature `{}` depends \
                           on itself", feat)
                }
                used.insert(feat.to_string());
                match s.features().get(feat) {
                    Some(recursive) => {
                        for f in recursive {
                            try!(add_feature(s, f, deps, used, visited));
                        }
                    }
                    None => {
                        deps.entry(feat.to_string()).or_insert(Vec::new());
                    }
                }
                visited.remove(&feat.to_string());
            }
        }
        Ok(())
    }
}
// Returns a pair of (feature dependencies, all used features)
//
// The feature dependencies map is a mapping of package name to list of features
// enabled. Each package should be enabled, and each package should have the
// specified set of features enabled.
//
// The all used features set is the set of features which this local package had
// enabled, which is later used when compiling to instruct the code what
// features were enabled.
Returns a pair of (feature dependencies, all used features)
The feature dependencies map is a mapping of package name to list of features
enabled. Each package should be enabled, and each package should have the
specified set of features enabled.

The all used features set is the set of features which this local package had
enabled, which is later used when compiling to instruct the code what
features were enabled.
Returns a pair of ( feature dependencies all used features ) The feature dependencies map is a mapping of package name to list of features enabled . Each package should be enabled and each package should have the specified set of features enabled . The all used features set is the set of features which this local package had enabled which is later used when compiling to instruct the code what features were enabled .
fn build_features(s: &Summary, method: &Method)
                  -> CargoResult<(HashMap<String, Vec<String>>, HashSet<String>)> {
    let mut deps = HashMap::new();
    let mut used = HashSet::new();
    let mut visited = HashSet::new();
    match *method {
        Method::Everything => {
            for key in s.features().keys() {
                try!(add_feature(s, key, &mut deps, &mut used, &mut visited));
            }
            for dep in s.dependencies().iter().filter(|d| d.is_optional()) {
                try!(add_feature(s, dep.name(), &mut deps, &mut used,
                                 &mut visited));
            }
        }
        Method::Required { features: requested_features, .. } =>  {
            for feat in requested_features.iter() {
                try!(add_feature(s, feat, &mut deps, &mut used, &mut visited));
            }
        }
    }
    match *method {
        Method::Everything |
        Method::Required { uses_default_features: true, .. } => {
            if s.features().get("default").is_some() {
                try!(add_feature(s, "default", &mut deps, &mut used,
                                 &mut visited));
            }
        }
        Method::Required { uses_default_features: false, .. } => {}
    }
    return Ok((deps, used));
    fn add_feature(s: &Summary, feat: &str,
                   deps: &mut HashMap<String, Vec<String>>,
                   used: &mut HashSet<String>,
                   visited: &mut HashSet<String>) -> CargoResult<()> {
        if feat.is_empty() { return Ok(()) }
        // If this feature is of the form `foo/bar`, then we just lookup package
        // `foo` and enable its feature `bar`. Otherwise this feature is of the
        // form `foo` and we need to recurse to enable the feature `foo` for our
        // own package, which may end up enabling more features or just enabling
        // a dependency.
        let mut parts = feat.splitn(2, '/');
        let feat_or_package = parts.next().unwrap();
        match parts.next() {
            Some(feat) => {
                let package = feat_or_package;
                used.insert(package.to_string());
                deps.entry(package.to_string())
                    .or_insert(Vec::new())
                    .push(feat.to_string());
            }
            None => {
                let feat = feat_or_package;
                if !visited.insert(feat.to_string()) {
                    bail!("Cyclic feature dependency: feature `{}` depends \
                           on itself", feat)
                }
                used.insert(feat.to_string());
                match s.features().get(feat) {
                    Some(recursive) => {
                        for f in recursive {
                            try!(add_feature(s, f, deps, used, visited));
                        }
                    }
                    None => {
                        deps.entry(feat.to_string()).or_insert(Vec::new());
                    }
                }
                visited.remove(&feat.to_string());
            }
        }
        Ok(())
    }
}
fn build_features ( s : & Summary , method : & Method ) -> CargoResult < ( HashMap < String , Vec < String > > , HashSet < String > ) > { let mut deps = HashMap :: new ( ) ; let mut used = HashSet :: new ( ) ; let mut visited = HashSet :: new ( ) ; match * method { Method :: Everything => { for key in s . features ( ) . keys ( ) { try ! ( add_feature ( s key mut deps mut used mut visited ) ) ; } for dep in s . dependencies ( ) . iter ( ) . filter ( | d | d . is_optional ( ) ) { try ! ( add_feature ( s dep name ( ) mut deps mut used mut visited ) ) ; } } Method :: Required { features : requested_features , .. } => { for feat in requested_features . iter ( ) { try ! ( add_feature ( s feat mut deps mut used mut visited ) ) ; } } } match * method { Method :: Everything | Method :: Required { uses_default_features : true , .. } => { if s . features ( ) . get ( " " ) . is_some ( ) { try ! ( add_feature ( s " " mut deps mut used mut visited ) ) ; } } Method :: Required { uses_default_features : false , .. } => { } } return Ok ( ( deps , used ) ) ; fn add_feature ( s : & Summary , feat : & str , deps : & mut HashMap < String , Vec < String > > , used : & mut HashSet < String > , visited : & mut HashSet < String > ) -> CargoResult < ( ) > { if feat . is_empty ( ) { return Ok ( ( ) ) } // If this feature is of the form `foo/bar`, then we just lookup package // `foo` and enable its feature `bar`. Otherwise this feature is of the // form `foo` and we need to recurse to enable the feature `foo` for our // own package, which may end up enabling more features or just enabling // a dependency. let mut parts = feat . splitn ( 2 , '/' ) ; let feat_or_package = parts . next ( ) . unwrap ( ) ; match parts . next ( ) { Some ( feat ) => { let package = feat_or_package ; used . insert ( package . to_string ( ) ) ; deps . entry ( package . to_string ( ) ) . or_insert ( Vec :: new ( ) ) . push ( feat . to_string ( ) ) ; } None => { let feat = feat_or_package ; if ! visited . insert ( feat . to_string ( ) ) { bail ! ( " \
 " feat ) } used . insert ( feat . to_string ( ) ) ; match s . features ( ) . get ( feat ) { Some ( recursive ) => { for f in recursive { try ! ( add_feature ( s f deps used visited ) ) ; } } None => { deps . entry ( feat . to_string ( ) ) . or_insert ( Vec :: new ( ) ) ; } } visited . remove ( & feat . to_string ( ) ) ; } } Ok ( ( ) ) } }
Returns a pair of (feature dependencies, all used features)
The feature dependencies map is a mapping of package name to list of features
enabled.
Returns a pair of ( feature dependencies all used features ) The feature dependencies map is a mapping of package name to list of features enabled .
s
&Summary
method
&Method
s
&Summary
method
&Method