fn collect_matching_features(
        member: &Package,
        cli_features: &CliFeatures,
        found_features: &mut BTreeSet<FeatureValue>,
    ) -> CliFeatures {
        if cli_features.features.is_empty() || cli_features.all_features {
            return cli_features.clone();
        }

        // Only include features this member defines.
        let summary = member.summary();

        // Features defined in the manifest
        let summary_features = summary.features();

        // Dependency name -> dependency
        let dependencies: BTreeMap<InternedString, &Dependency> = summary
            .dependencies()
            .iter()
            .map(|dep| (dep.name_in_toml(), dep))
            .collect();

        // Features that enable optional dependencies
        let optional_dependency_names: BTreeSet<_> = dependencies
            .iter()
            .filter(|(_, dep)| dep.is_optional())
            .map(|(name, _)| name)
            .copied()
            .collect();

        let mut features = BTreeSet::new();

        // Checks if a member contains the given feature.
        let summary_or_opt_dependency_feature = |feature: &InternedString| -> bool {
            summary_features.contains_key(feature) || optional_dependency_names.contains(feature)
        };

        for feature in cli_features.features.iter() {
            match feature {
                FeatureValue::Feature(f) => {
                    if summary_or_opt_dependency_feature(f) {
                        // feature exists in this member.
                        features.insert(feature.clone());
                        found_features.insert(feature.clone());
                    }
                }
                // This should be enforced by CliFeatures.
                FeatureValue::Dep { .. } => panic!("unexpected dep: syntax {}", feature),
                FeatureValue::DepFeature {
                    dep_name,
                    dep_feature,
                    weak: _,
                } => {
                    if dependencies.contains_key(dep_name) {
                        // pkg/feat for a dependency.
                        // Will rely on the dependency resolver to validate `dep_feature`.
                        features.insert(feature.clone());
                        found_features.insert(feature.clone());
                    } else if *dep_name == member.name()
                        && summary_or_opt_dependency_feature(dep_feature)
                    {
                        // member/feat where "feat" is a feature in member.
                        //
                        // `weak` can be ignored here, because the member
                        // either is or isn't being built.
                        features.insert(FeatureValue::Feature(*dep_feature));
                        found_features.insert(feature.clone());
                    }
                }
            }
        }
        CliFeatures {
            features: Rc::new(features),
            all_features: false,
            uses_default_features: cli_features.uses_default_features,
        }
    }
/// Returns the requested features for the given member.
/// This filters out any named features that the member does not have.
Returns the requested features for the given member.
This filters out any named features that the member does not have.
Returns the requested features for the given member . This filters out any named features that the member does not have .
fn collect_matching_features(
        member: &Package,
        cli_features: &CliFeatures,
        found_features: &mut BTreeSet<FeatureValue>,
    ) -> CliFeatures {
        if cli_features.features.is_empty() || cli_features.all_features {
            return cli_features.clone();
        }
        // Only include features this member defines.
        let summary = member.summary();
        // Features defined in the manifest
        let summary_features = summary.features();
        // Dependency name -> dependency
        let dependencies: BTreeMap<InternedString, &Dependency> = summary
            .dependencies()
            .iter()
            .map(|dep| (dep.name_in_toml(), dep))
            .collect();
        // Features that enable optional dependencies
        let optional_dependency_names: BTreeSet<_> = dependencies
            .iter()
            .filter(|(_, dep)| dep.is_optional())
            .map(|(name, _)| name)
            .copied()
            .collect();
        let mut features = BTreeSet::new();
        // Checks if a member contains the given feature.
        let summary_or_opt_dependency_feature = |feature: &InternedString| -> bool {
            summary_features.contains_key(feature) || optional_dependency_names.contains(feature)
        };
        for feature in cli_features.features.iter() {
            match feature {
                FeatureValue::Feature(f) => {
                    if summary_or_opt_dependency_feature(f) {
                        // feature exists in this member.
                        features.insert(feature.clone());
                        found_features.insert(feature.clone());
                    }
                }
                // This should be enforced by CliFeatures.
                FeatureValue::Dep { .. } => panic!("unexpected dep: syntax {}", feature),
                FeatureValue::DepFeature {
                    dep_name,
                    dep_feature,
                    weak: _,
                } => {
                    if dependencies.contains_key(dep_name) {
                        // pkg/feat for a dependency.
                        // Will rely on the dependency resolver to validate `dep_feature`.
                        features.insert(feature.clone());
                        found_features.insert(feature.clone());
                    } else if *dep_name == member.name()
                        && summary_or_opt_dependency_feature(dep_feature)
                    {
                        // member/feat where "feat" is a feature in member.
                        //
                        // `weak` can be ignored here, because the member
                        // either is or isn't being built.
                        features.insert(FeatureValue::Feature(*dep_feature));
                        found_features.insert(feature.clone());
                    }
                }
            }
        }
        CliFeatures {
            features: Rc::new(features),
            all_features: false,
            uses_default_features: cli_features.uses_default_features,
        }
    }
fn collect_matching_features ( member : & Package , cli_features : & CliFeatures , found_features : & mut BTreeSet < FeatureValue > , ) -> CliFeatures { if cli_features . features . is_empty ( ) || cli_features . all_features { return cli_features . clone ( ) ; } // Only include features this member defines. let summary = member . summary ( ) ; // Features defined in the manifest let summary_features = summary . features ( ) ; // Dependency name -> dependency let dependencies : BTreeMap < InternedString , & Dependency > = summary . dependencies ( ) . iter ( ) . map ( | dep | ( dep . name_in_toml ( ) , dep ) ) . collect ( ) ; // Features that enable optional dependencies let optional_dependency_names : BTreeSet < _ > = dependencies . iter ( ) . filter ( | ( _ , dep ) | dep . is_optional ( ) ) . map ( | ( name , _ ) | name ) . copied ( ) . collect ( ) ; let mut features = BTreeSet :: new ( ) ; // Checks if a member contains the given feature. let summary_or_opt_dependency_feature = | feature : & InternedString | -> bool { summary_features . contains_key ( feature ) || optional_dependency_names . contains ( feature ) } ; for feature in cli_features . features . iter ( ) { match feature { FeatureValue :: Feature ( f ) => { if summary_or_opt_dependency_feature ( f ) { // feature exists in this member. features . insert ( feature . clone ( ) ) ; found_features . insert ( feature . clone ( ) ) ; } } // This should be enforced by CliFeatures. FeatureValue :: Dep { .. } => panic ! ( " " feature ) , FeatureValue :: DepFeature { dep_name , dep_feature , weak : _ , } => { if dependencies . contains_key ( dep_name ) { // pkg/feat for a dependency. // Will rely on the dependency resolver to validate `dep_feature`. features . insert ( feature . clone ( ) ) ; found_features . insert ( feature . clone ( ) ) ; } else if * dep_name == member . name ( ) && summary_or_opt_dependency_feature ( dep_feature ) { // member/feat where "feat" is a feature in member. // // `weak` can be ignored here, because the member // either is or isn't being built. features . insert ( FeatureValue :: Feature ( * dep_feature ) ) ; found_features . insert ( feature . clone ( ) ) ; } } } } CliFeatures { features : Rc :: new ( features ) , all_features : false , uses_default_features : cli_features . uses_default_features , } }
Returns the requested features for the given member.
Returns the requested features for the given member .
member
&Package
cli_features
&CliFeatures
found_features
&mut BTreeSet<FeatureValue>
member
&Package
cli_features
&CliFeatures
found_features
&mut BTreeSet<FeatureValue>