summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-06-29 10:00:43 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-09-16 12:32:22 +0200
commit708adfc6bd494d5ca8be9d7826a967d02c5d82b9 (patch)
treeb07e79bd5873b6fd40c05577239a1d5c6a42e9c9
parent8c8c75ee6a12d4b613b87f05d922c0495b3f9dee (diff)
Refactor: Outsource condition-checking and parsing to helper fn
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/package/dag.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/package/dag.rs b/src/package/dag.rs
index fd31132..c805121 100644
--- a/src/package/dag.rs
+++ b/src/package/dag.rs
@@ -51,6 +51,19 @@ impl Dag {
conditional_data: &ConditionData<'_>, // required for selecting packages with conditional dependencies
) -> Result<Self> {
+ /// helper fn with bad name to check the dependency condition of a dependency and parse the dependency into a tuple of
+ /// name and version for further processing
+ fn process<D: ConditionCheckable + ParseDependency>(d: &D, conditional_data: &ConditionData<'_>)
+ -> Result<(bool, PackageName, PackageVersionConstraint)>
+ {
+ // Check whether the condition of the dependency matches our data
+ let take = d.check_condition(conditional_data)?;
+ let (name, version) = d.parse_as_name_and_version()?;
+
+ // (dependency check result, name of the dependency, version of the dependency)
+ Ok((take, name, version))
+ }
+
/// Helper fn to get the dependencies of a package
///
/// This function helps getting the dependencies of a package as an iterator over
@@ -61,32 +74,17 @@ impl Dag {
fn get_package_dependencies<'a>(package: &'a Package, conditional_data: &'a ConditionData<'_>)
-> impl Iterator<Item = Result<(PackageName, PackageVersionConstraint)>> + 'a
{
- let build_dependencies = package.dependencies()
- .build()
- .iter()
- .map(move |d| {
- // Check whether the condition of the dependency matches our data
- let take = d.check_condition(conditional_data)?;
- let (name, version) = d.parse_as_name_and_version()?;
- // (dependency check result, name of the dependency, version of the dependency)
- Ok((take, name, version))
- });
-
- let runtime_dependencies = package.dependencies()
- .runtime()
+ package.dependencies()
+ .build()
.iter()
- .map(move |d| {
- // Check whether the condition of the dependency matches our data
- let take = d.check_condition(conditional_data)?;
- let (name, version) = d.parse_as_name_and_version()?;
-
- // (dependency check result, name of the dependency, version of the dependency)
- Ok((take, name, version))
- });
-
- build_dependencies
- .chain(runtime_dependencies)
+ .map(move |d| process(d, conditional_data))
+ .chain({
+ package.dependencies()
+ .runtime()
+ .iter()
+ .map(move |d| process(d, conditional_data))
+ })
// Now filter out all dependencies where their condition did not match our
// `conditional_data`.