From 330fdc72764e6f4b94b79df507d6d03f229ff09c Mon Sep 17 00:00:00 2001 From: Zanie Date: Thu, 7 Dec 2023 19:30:00 -0600 Subject: [PATCH] Add `DeriviationTree.packages -> HashSet<&P>` --- src/report.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/report.rs b/src/report.rs index 29c60fac..c0107ecd 100644 --- a/src/report.rs +++ b/src/report.rs @@ -3,6 +3,7 @@ //! Build a report as clear as possible as to why //! dependency solving failed. +use std::collections::HashSet; use std::fmt; use std::ops::{Deref, DerefMut}; @@ -72,6 +73,31 @@ pub struct Derived { } impl DerivationTree { + /// Get all [Package]s referred to in the deriviation tree. + pub fn packages(&self) -> HashSet<&P> { + let mut packages = HashSet::default(); + match self { + Self::External(external) => match external { + External::FromDependencyOf(p, _, p2, _) => { + packages.insert(p); + packages.insert(p2); + } + External::NoVersions(p, _) + | External::NotRoot(p, _) + | External::UnavailableDependencies(p, _) + | External::UnusableDependencies(p, ..) => { + packages.insert(p); + } + }, + Self::Derived(derived) => { + packages.extend(derived.terms.keys()); + packages.extend(derived.cause1.packages().iter()); + packages.extend(derived.cause2.packages().iter()); + } + } + packages + } + /// Merge the [NoVersions](External::NoVersions) external incompatibilities /// with the other one they are matched with /// in a derived incompatibility.