From 8628442d872e24ed1aca3d9da8fef3d7e03f66cb Mon Sep 17 00:00:00 2001 From: konstin Date: Wed, 11 Dec 2024 10:54:36 +0100 Subject: [PATCH] Merge partial solution impl blocks There were two identical impl block for `impl PartialSolution`, so I merged them. I've also reduced the visibility since `PartialSolution` is also `pub(crate)`. --- src/internal/partial_solution.rs | 52 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index c6328aac..1c90f3cb 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -51,33 +51,6 @@ pub(crate) struct PartialSolution { has_ever_backtracked: bool, } -impl PartialSolution { - pub fn display<'a>(&'a self, package_store: &'a HashArena) -> impl Display + 'a { - struct PSDisplay<'a, DP: DependencyProvider>(&'a PartialSolution, &'a HashArena); - - impl Display for PSDisplay<'_, DP> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut assignments: Vec<_> = self - .0 - .package_assignments - .iter() - .map(|(p, pa)| format!("{:?} = '{}': {}", p, self.1[*p], pa)) - .collect(); - assignments.sort(); - write!( - f, - "next_global_index: {}\ncurrent_decision_level: {:?}\npackage_assignments:\n{}", - self.0.next_global_index, - self.0.current_decision_level, - assignments.join("\t\n") - ) - } - } - - PSDisplay(self, package_store) - } -} - /// Package assignments contain the potential decision and derivations /// that have already been made for a given package, /// as well as the intersection of terms by all of these. @@ -167,6 +140,31 @@ impl PartialSolution { } } + pub(crate) fn display<'a>(&'a self, package_store: &'a HashArena) -> impl Display + 'a { + struct PSDisplay<'a, DP: DependencyProvider>(&'a PartialSolution, &'a HashArena); + + impl Display for PSDisplay<'_, DP> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let mut assignments: Vec<_> = self + .0 + .package_assignments + .iter() + .map(|(p, pa)| format!("{:?} = '{}': {}", p, self.1[*p], pa)) + .collect(); + assignments.sort(); + write!( + f, + "next_global_index: {}\ncurrent_decision_level: {:?}\npackage_assignments:\n{}", + self.0.next_global_index, + self.0.current_decision_level, + assignments.join("\t\n") + ) + } + } + + PSDisplay(self, package_store) + } + /// Add a decision. pub(crate) fn add_decision(&mut self, package: Id, version: DP::V) { // Check that add_decision is never used in the wrong context.