diff options
Diffstat (limited to 'crates/shirabe/src')
30 files changed, 201 insertions, 185 deletions
diff --git a/crates/shirabe/src/command/suggests_command.rs b/crates/shirabe/src/command/suggests_command.rs index 317b9c4..1f43070 100644 --- a/crates/shirabe/src/command/suggests_command.rs +++ b/crates/shirabe/src/command/suggests_command.rs @@ -23,7 +23,7 @@ pub struct SuggestsCommand { composer: Option<Composer>, io: Option<Box<dyn IOInterface>>, - completion_trait: CompletionTrait, + completion_trait: Box<dyn CompletionTrait>, } impl SuggestsCommand { diff --git a/crates/shirabe/src/dependency_resolver/decisions.rs b/crates/shirabe/src/dependency_resolver/decisions.rs index 22b6fa4..8ef8b25 100644 --- a/crates/shirabe/src/dependency_resolver/decisions.rs +++ b/crates/shirabe/src/dependency_resolver/decisions.rs @@ -11,7 +11,7 @@ use std::fmt; pub struct Decisions { pub(crate) pool: Pool, pub(crate) decision_map: IndexMap<i64, i64>, - pub(crate) decision_queue: Vec<(i64, Rule)>, + pub(crate) decision_queue: Vec<(i64, Box<dyn Rule>)>, iterator_cursor: Option<usize>, } @@ -28,7 +28,7 @@ impl Decisions { } } - pub fn decide(&mut self, literal: i64, level: i64, why: Rule) { + pub fn decide(&mut self, literal: i64, level: i64, why: Box<dyn Rule>) { self.add_decision(literal, level); self.decision_queue.push((literal, why)); } @@ -82,12 +82,12 @@ impl Decisions { 0 } - pub fn decision_rule(&self, literal_or_package_id: i64) -> &Rule { + pub fn decision_rule(&self, literal_or_package_id: i64) -> &dyn Rule { let package_id = literal_or_package_id.abs(); for decision in &self.decision_queue { if package_id == decision.0.abs() { - return &decision.1; + return &*decision.1; } } @@ -104,7 +104,7 @@ impl Decisions { ); } - pub fn at_offset(&self, queue_offset: usize) -> &(i64, Rule) { + pub fn at_offset(&self, queue_offset: usize) -> &(i64, Box<dyn Rule>) { &self.decision_queue[queue_offset] } @@ -112,8 +112,8 @@ impl Decisions { queue_offset >= 0 && queue_offset < self.decision_queue.len() as i64 } - pub fn last_reason(&self) -> &Rule { - &self.decision_queue[self.decision_queue.len() - 1].1 + pub fn last_reason(&self) -> &dyn Rule { + &*self.decision_queue[self.decision_queue.len() - 1].1 } pub fn last_literal(&self) -> i64 { @@ -151,7 +151,7 @@ impl Decisions { } } - pub fn current(&self) -> Option<&(i64, Rule)> { + pub fn current(&self) -> Option<&(i64, Box<dyn Rule>)> { self.iterator_cursor .and_then(|cursor| self.decision_queue.get(cursor)) } diff --git a/crates/shirabe/src/dependency_resolver/default_policy.rs b/crates/shirabe/src/dependency_resolver/default_policy.rs index f647327..378d0f8 100644 --- a/crates/shirabe/src/dependency_resolver/default_policy.rs +++ b/crates/shirabe/src/dependency_resolver/default_policy.rs @@ -45,8 +45,8 @@ impl DefaultPolicy { pub fn compare_by_priority( &self, pool: &Pool, - a: &BasePackage, - b: &BasePackage, + a: &dyn BasePackage, + b: &dyn BasePackage, required_package: Option<String>, ignore_replace: bool, ) -> i64 { @@ -169,7 +169,7 @@ impl DefaultPolicy { selected } - pub(crate) fn replaces(&self, source: &BasePackage, target: &BasePackage) -> bool { + pub(crate) fn replaces(&self, source: &dyn BasePackage, target: &dyn BasePackage) -> bool { for link in source.get_replaces().values() { if link.get_target() == target.get_name() { return true; diff --git a/crates/shirabe/src/dependency_resolver/pool.rs b/crates/shirabe/src/dependency_resolver/pool.rs index e86e4c2..5a028a1 100644 --- a/crates/shirabe/src/dependency_resolver/pool.rs +++ b/crates/shirabe/src/dependency_resolver/pool.rs @@ -16,15 +16,15 @@ use crate::package::version::version_parser::VersionParser; #[derive(Debug)] pub struct Pool { /// @var BasePackage[] - pub(crate) packages: Vec<Box<BasePackage>>, + pub(crate) packages: Vec<Box<dyn BasePackage>>, /// @var array<string, BasePackage[]> - pub(crate) package_by_name: IndexMap<String, Vec<Box<BasePackage>>>, + pub(crate) package_by_name: IndexMap<String, Vec<Box<dyn BasePackage>>>, /// @var VersionParser pub(crate) version_parser: VersionParser, /// @var array<string, array<string, BasePackage[]>> - pub(crate) provider_cache: IndexMap<String, IndexMap<String, Vec<Box<BasePackage>>>>, + pub(crate) provider_cache: IndexMap<String, IndexMap<String, Vec<Box<dyn BasePackage>>>>, /// @var BasePackage[] - pub(crate) unacceptable_fixed_or_locked_packages: Vec<Box<BasePackage>>, + pub(crate) unacceptable_fixed_or_locked_packages: Vec<Box<dyn BasePackage>>, /// @var array<string, array<string, string>> Map of package name => normalized version => pretty version pub(crate) removed_versions: IndexMap<String, IndexMap<String, String>>, /// @var array<string, array<string, string>> Map of package object hash => removed normalized versions => removed pretty version @@ -44,8 +44,8 @@ impl Pool { /// @param array<string, array<string, array<SecurityAdvisory|PartialSecurityAdvisory>>> $securityRemovedVersions /// @param array<string, array<string, string>> $abandonedRemovedVersions pub fn new( - packages: Vec<Box<BasePackage>>, - unacceptable_fixed_or_locked_packages: Vec<Box<BasePackage>>, + packages: Vec<Box<dyn BasePackage>>, + unacceptable_fixed_or_locked_packages: Vec<Box<dyn BasePackage>>, removed_versions: IndexMap<String, IndexMap<String, String>>, removed_versions_by_package: IndexMap<String, IndexMap<String, String>>, security_removed_versions: IndexMap<String, IndexMap<String, Vec<PartialSecurityAdvisory>>>, @@ -189,7 +189,7 @@ impl Pool { } /// @param BasePackage[] $packages - fn set_packages(&mut self, packages: Vec<Box<BasePackage>>) { + fn set_packages(&mut self, packages: Vec<Box<dyn BasePackage>>) { let mut id: i64 = 1; for mut package in packages { @@ -208,12 +208,12 @@ impl Pool { } /// @return BasePackage[] - pub fn get_packages(&self) -> &Vec<Box<BasePackage>> { + pub fn get_packages(&self) -> &Vec<Box<dyn BasePackage>> { &self.packages } /// Retrieves the package object for a given package id. - pub fn package_by_id(&self, id: i64) -> &BasePackage { + pub fn package_by_id(&self, id: i64) -> &dyn BasePackage { &self.packages[(id - 1) as usize] } @@ -227,7 +227,7 @@ impl Pool { &mut self, name: &str, constraint: Option<&dyn ConstraintInterface>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { // PHP: $key = (string) $constraint; let key = match constraint { Some(c) => c.to_string(), @@ -255,12 +255,12 @@ impl Pool { &self, name: &str, constraint: Option<&dyn ConstraintInterface>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { let Some(candidates) = self.package_by_name.get(name) else { return vec![]; }; - let mut matches: Vec<Box<BasePackage>> = vec![]; + let mut matches: Vec<Box<dyn BasePackage>> = vec![]; for candidate in candidates { if self.r#match(candidate, name, constraint) { @@ -271,7 +271,7 @@ impl Pool { matches } - pub fn literal_to_package(&self, literal: i64) -> &BasePackage { + pub fn literal_to_package(&self, literal: i64) -> &dyn BasePackage { let package_id = abs(literal); self.package_by_id(package_id) @@ -281,7 +281,7 @@ impl Pool { pub fn literal_to_pretty_string( &self, literal: i64, - installed_map: &IndexMap<i64, Box<BasePackage>>, + installed_map: &IndexMap<i64, Box<dyn BasePackage>>, ) -> String { let package = self.literal_to_package(literal); @@ -304,7 +304,7 @@ impl Pool { /// @param string $name Name of the package to be matched pub fn r#match( &self, - candidate: &BasePackage, + candidate: &dyn BasePackage, name: &str, constraint: Option<&dyn ConstraintInterface>, ) -> bool { @@ -362,7 +362,7 @@ impl Pool { false } - pub fn is_unacceptable_fixed_or_locked_package(&self, package: &BasePackage) -> bool { + pub fn is_unacceptable_fixed_or_locked_package(&self, package: &dyn BasePackage) -> bool { // PHP: \in_array($package, $this->unacceptableFixedOrLockedPackages, true) // strict comparison checks reference identity for objects let target_hash = spl_object_hash(package); @@ -372,7 +372,7 @@ impl Pool { } /// @return BasePackage[] - pub fn get_unacceptable_fixed_or_locked_packages(&self) -> &Vec<Box<BasePackage>> { + pub fn get_unacceptable_fixed_or_locked_packages(&self) -> &Vec<Box<dyn BasePackage>> { &self.unacceptable_fixed_or_locked_packages } } diff --git a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs index b71af14..094bd8d 100644 --- a/crates/shirabe/src/dependency_resolver/pool_optimizer.rs +++ b/crates/shirabe/src/dependency_resolver/pool_optimizer.rs @@ -39,7 +39,7 @@ pub struct PoolOptimizer { packages_to_remove: IndexMap<i64, bool>, /// @var array<int, BasePackage[]> - aliases_per_package: IndexMap<i64, Vec<Box<BasePackage>>>, + aliases_per_package: IndexMap<i64, Vec<Box<dyn BasePackage>>>, /// @var array<string, array<string, string>> removed_versions_by_package: IndexMap<String, IndexMap<String, String>>, @@ -171,7 +171,7 @@ impl PoolOptimizer { } } - fn mark_package_irremovable(&mut self, package: &BasePackage) { + fn mark_package_irremovable(&mut self, package: &dyn BasePackage) { self.irremovable_packages.insert(package.id, true); if let Some(alias_pkg) = (package.as_any() as &dyn Any).downcast_ref::<AliasPackage>() { // recursing here so aliasesPerPackage for the aliasOf can be checked @@ -191,7 +191,7 @@ impl PoolOptimizer { /// @return Pool Optimized pool fn apply_removals_to_pool(&self, pool: &Pool) -> Pool { - let mut packages: Vec<Box<BasePackage>> = vec![]; + let mut packages: Vec<Box<dyn BasePackage>> = vec![]; let mut removed_versions: IndexMap<String, IndexMap<String, String>> = IndexMap::new(); for package in pool.get_packages() { if !self.packages_to_remove.contains_key(&package.id) { @@ -225,7 +225,7 @@ impl PoolOptimizer { ) -> Result<()> { let mut identical_definitions_per_package: IndexMap< String, - IndexMap<String, IndexMap<String, Vec<Box<BasePackage>>>>, + IndexMap<String, IndexMap<String, Vec<Box<dyn BasePackage>>>>, > = IndexMap::new(); let mut package_identical_definition_lookup: IndexMap< i64, @@ -361,7 +361,7 @@ impl PoolOptimizer { Ok(()) } - fn calculate_dependency_hash(&self, package: &BasePackage) -> String { + fn calculate_dependency_hash(&self, package: &dyn BasePackage) -> String { let mut hash = String::new(); let hash_relevant_links: Vec<(&str, Vec<crate::package::link::Link>)> = vec![ @@ -425,10 +425,10 @@ impl PoolOptimizer { /// @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup fn keep_package( &mut self, - package: &BasePackage, + package: &dyn BasePackage, identical_definitions_per_package: &IndexMap< String, - IndexMap<String, IndexMap<String, Vec<Box<BasePackage>>>>, + IndexMap<String, IndexMap<String, Vec<Box<dyn BasePackage>>>>, >, package_identical_definition_lookup: &IndexMap< i64, @@ -542,7 +542,8 @@ impl PoolOptimizer { return; } - let mut package_index: IndexMap<String, IndexMap<i64, Box<BasePackage>>> = IndexMap::new(); + let mut package_index: IndexMap<String, IndexMap<i64, Box<dyn BasePackage>>> = + IndexMap::new(); for package in pool.get_packages() { let id = package.id; diff --git a/crates/shirabe/src/dependency_resolver/problem.rs b/crates/shirabe/src/dependency_resolver/problem.rs index 50b651d..adc2f43 100644 --- a/crates/shirabe/src/dependency_resolver/problem.rs +++ b/crates/shirabe/src/dependency_resolver/problem.rs @@ -35,7 +35,7 @@ pub struct Problem { pub(crate) reason_seen: IndexMap<String, bool>, /// A set of reasons for the problem, each is a rule or a root require and a rule - pub(crate) reasons: IndexMap<i64, Vec<Rule>>, + pub(crate) reasons: IndexMap<i64, Vec<Box<dyn Rule>>>, pub(crate) section: i64, } @@ -50,13 +50,13 @@ impl Problem { } /// Add a rule as a reason - pub fn add_rule(&mut self, rule: Rule) { + pub fn add_rule(&mut self, rule: Box<dyn Rule>) { let id = spl_object_hash(&rule); self.add_reason(id, rule); } /// Retrieve all reasons for this problem - pub fn get_reasons(&self) -> &IndexMap<i64, Vec<Rule>> { + pub fn get_reasons(&self) -> &IndexMap<i64, Vec<Box<dyn Rule>>> { &self.reasons } @@ -67,11 +67,11 @@ impl Problem { request: &Request, pool: &Pool, is_verbose: bool, - installed_map: &IndexMap<String, BasePackage>, - learned_pool: &Vec<Vec<Rule>>, + installed_map: &IndexMap<String, Box<dyn BasePackage>>, + learned_pool: &Vec<Vec<Box<dyn Rule>>>, ) -> anyhow::Result<String> { // TODO doesn't this entirely defeat the purpose of the problem sections? what's the point of sections? - let mut reasons: Vec<Rule> = Vec::new(); + let mut reasons: Vec<Box<dyn Rule>> = Vec::new(); for section_rules in self.reasons.values().rev() { for rule in section_rules { reasons.push(rule.clone()); @@ -132,7 +132,7 @@ impl Problem { )) } - fn get_sortable_string(&self, pool: &Pool, rule: &Rule) -> String { + fn get_sortable_string(&self, pool: &Pool, rule: &dyn Rule) -> String { match rule.get_reason() { Rule::RULE_ROOT_REQUIRE => rule.get_reason_data().as_array().unwrap()["packageName"] .as_string() @@ -170,7 +170,7 @@ impl Problem { } } - fn get_rule_priority(&self, rule: &Rule) -> i64 { + fn get_rule_priority(&self, rule: &dyn Rule) -> i64 { match rule.get_reason() { Rule::RULE_FIXED => 3, Rule::RULE_ROOT_REQUIRE => 2, @@ -188,14 +188,14 @@ impl Problem { /// @internal pub fn format_deduplicated_rules( - rules: &Vec<Rule>, + rules: &Vec<Box<dyn Rule>>, indent: &str, repository_set: &RepositorySet, request: &Request, pool: &Pool, is_verbose: bool, - installed_map: &IndexMap<String, BasePackage>, - learned_pool: &Vec<Vec<Rule>>, + installed_map: &IndexMap<String, Box<dyn BasePackage>>, + learned_pool: &Vec<Vec<Box<dyn Rule>>>, ) -> String { let mut messages: Vec<String> = Vec::new(); let mut templates: IndexMap<String, IndexMap<String, IndexMap<String, String>>> = @@ -350,7 +350,7 @@ impl Problem { } /// Store a reason descriptor but ignore duplicates - pub(crate) fn add_reason(&mut self, id: String, reason: Rule) { + pub(crate) fn add_reason(&mut self, id: String, reason: Box<dyn Rule>) { // TODO: if a rule is part of a problem description in two sections, isn't this going to remove a message // that is important to understand the issue? diff --git a/crates/shirabe/src/dependency_resolver/request.rs b/crates/shirabe/src/dependency_resolver/request.rs index e1f8c1e..0d11296 100644 --- a/crates/shirabe/src/dependency_resolver/request.rs +++ b/crates/shirabe/src/dependency_resolver/request.rs @@ -35,9 +35,9 @@ pub enum UpdateAllowTransitiveDeps { pub struct Request { pub(crate) locked_repository: Option<LockArrayRepository>, pub(crate) requires: IndexMap<String, Box<dyn ConstraintInterface>>, - pub(crate) fixed_packages: IndexMap<String, BasePackage>, - pub(crate) locked_packages: IndexMap<String, BasePackage>, - pub(crate) fixed_locked_packages: IndexMap<String, BasePackage>, + pub(crate) fixed_packages: IndexMap<String, Box<dyn BasePackage>>, + pub(crate) locked_packages: IndexMap<String, Box<dyn BasePackage>>, + pub(crate) fixed_locked_packages: IndexMap<String, Box<dyn BasePackage>>, pub(crate) update_allow_list: Vec<String>, pub(crate) update_allow_transitive_dependencies: UpdateAllowTransitiveDeps, restrict_packages: Option<Vec<String>>, @@ -85,7 +85,7 @@ impl Request { /// This is used for platform packages which cannot be modified by Composer. A rule enforcing /// their installation is generated for dependency resolution. Partial updates with dependencies /// cannot in any way modify these packages. - pub fn fix_package(&mut self, package: BasePackage) { + pub fn fix_package(&mut self, package: Box<dyn BasePackage>) { let hash = spl_object_hash(&package); self.fixed_packages.insert(hash, package); } @@ -100,7 +100,7 @@ impl Request { /// for the solver, so if nothing requires these packages they will be removed. Additionally in /// a partial update these packages can be unlocked, meaning other versions can be installed if /// explicitly requested as part of the update. - pub fn lock_package(&mut self, package: BasePackage) { + pub fn lock_package(&mut self, package: Box<dyn BasePackage>) { let hash = spl_object_hash(&package); self.locked_packages.insert(hash, package); } @@ -111,13 +111,13 @@ impl Request { /// should not allow removal of any packages. At the same time lock packages there cannot simply /// be marked fixed, as error reporting would then report them as platform packages, so this /// still marks them as locked packages at the same time. - pub fn fix_locked_package(&mut self, package: BasePackage) { + pub fn fix_locked_package(&mut self, package: Box<dyn BasePackage>) { let hash = spl_object_hash(&package); self.fixed_packages.insert(hash.clone(), package.clone()); self.fixed_locked_packages.insert(hash, package); } - pub fn unlock_package(&mut self, package: &BasePackage) { + pub fn unlock_package(&mut self, package: &dyn BasePackage) { self.locked_packages.remove(&spl_object_hash(package)); } @@ -149,15 +149,15 @@ impl Request { &self.requires } - pub fn get_fixed_packages(&self) -> &IndexMap<String, BasePackage> { + pub fn get_fixed_packages(&self) -> &IndexMap<String, Box<dyn BasePackage>> { &self.fixed_packages } - pub fn is_fixed_package(&self, package: &BasePackage) -> bool { + pub fn is_fixed_package(&self, package: &dyn BasePackage) -> bool { self.fixed_packages.contains_key(&spl_object_hash(package)) } - pub fn get_locked_packages(&self) -> &IndexMap<String, BasePackage> { + pub fn get_locked_packages(&self) -> &IndexMap<String, Box<dyn BasePackage>> { &self.locked_packages } @@ -166,7 +166,7 @@ impl Request { self.locked_packages.contains_key(&hash) || self.fixed_locked_packages.contains_key(&hash) } - pub fn get_fixed_or_locked_packages(&self) -> IndexMap<String, BasePackage> { + pub fn get_fixed_or_locked_packages(&self) -> IndexMap<String, Box<dyn BasePackage>> { let mut result = self.fixed_packages.clone(); result.extend(self.locked_packages.clone()); result @@ -176,8 +176,8 @@ impl Request { /// is for the installed map in the solver problems. /// Some locked packages may not be in the pool, /// so they have a package->id of -1 - pub fn get_present_map(&self, package_ids: bool) -> IndexMap<String, BasePackage> { - let mut present_map: IndexMap<String, BasePackage> = IndexMap::new(); + pub fn get_present_map(&self, package_ids: bool) -> IndexMap<String, Box<dyn BasePackage>> { + let mut present_map: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); if let Some(ref locked_repository) = self.locked_repository { for package in locked_repository.get_packages() { @@ -202,8 +202,8 @@ impl Request { present_map } - pub fn get_fixed_packages_map(&self) -> IndexMap<i64, BasePackage> { - let mut fixed_packages_map: IndexMap<i64, BasePackage> = IndexMap::new(); + pub fn get_fixed_packages_map(&self) -> IndexMap<i64, Box<dyn BasePackage>> { + let mut fixed_packages_map: IndexMap<i64, Box<dyn BasePackage>> = IndexMap::new(); for (_, package) in &self.fixed_packages { fixed_packages_map.insert(package.get_id(), package.clone()); } diff --git a/crates/shirabe/src/dependency_resolver/rule.rs b/crates/shirabe/src/dependency_resolver/rule.rs index 654be92..eb8d2a0 100644 --- a/crates/shirabe/src/dependency_resolver/rule.rs +++ b/crates/shirabe/src/dependency_resolver/rule.rs @@ -27,7 +27,7 @@ use crate::repository::repository_set::RepositorySet; #[derive(Debug)] pub enum ReasonData { Link(Link), - BasePackage(Box<BasePackage>), + BasePackage(Box<dyn BasePackage>), String(String), Int(i64), RootRequire { @@ -35,7 +35,7 @@ pub enum ReasonData { constraint: Box<dyn ConstraintInterface>, }, Fixed { - package: Box<BasePackage>, + package: Box<dyn BasePackage>, }, } @@ -151,7 +151,7 @@ pub trait Rule: std::fmt::Display { // TODO(phase-b): Request::get_locked_repository() signature if let Some(locked_repo) = todo!("request.get_locked_repository()") { for package in todo!("locked_repo.get_packages()") { - let p: &BasePackage = todo!("package as BasePackage reference"); + let p: &dyn BasePackage = todo!("package as BasePackage reference"); if p.get_name() == link.get_target() { if pool.is_unacceptable_fixed_or_locked_package(p) { return true; @@ -186,7 +186,7 @@ pub trait Rule: std::fmt::Display { // TODO(phase-b): Request::get_locked_repository() signature if let Some(locked_repo) = todo!("request.get_locked_repository()") { for package in todo!("locked_repo.get_packages()") { - let p: &BasePackage = todo!("package as BasePackage reference"); + let p: &dyn BasePackage = todo!("package as BasePackage reference"); if p.get_name() == package_name { if pool.is_unacceptable_fixed_or_locked_package(p) { return true; @@ -205,7 +205,7 @@ pub trait Rule: std::fmt::Display { } /// @internal - fn get_source_package(&self, pool: &Pool) -> Result<Box<BasePackage>> { + fn get_source_package(&self, pool: &Pool) -> Result<Box<dyn BasePackage>> { let literals = self.get_literals(); match self.get_reason() { @@ -250,7 +250,7 @@ pub trait Rule: std::fmt::Display { request: &Request, pool: &mut Pool, is_verbose: bool, - installed_map: IndexMap<i64, Box<BasePackage>>, + installed_map: IndexMap<i64, Box<dyn BasePackage>>, _learned_pool: IndexMap<i64, Vec<Box<dyn Rule>>>, ) -> String { let mut literals = self.get_literals(); @@ -277,7 +277,7 @@ pub trait Rule: std::fmt::Display { } // PHP: array_values(array_filter($packages, fn ($p) => !($p instanceof AliasPackage))) - let packages_non_alias: Vec<Box<BasePackage>> = packages + let packages_non_alias: Vec<Box<dyn BasePackage>> = packages .iter() .filter(|p| { (p.as_any() as &dyn Any) @@ -409,7 +409,7 @@ pub trait Rule: std::fmt::Display { _ => return String::new(), }; - let mut requires: Vec<Box<BasePackage>> = vec![]; + let mut requires: Vec<Box<dyn BasePackage>> = vec![]; for literal in &literals { requires.push(pool.literal_to_package(*literal)); } @@ -479,8 +479,8 @@ pub trait Rule: std::fmt::Display { reason_str }; - let mut installed_packages: Vec<Box<BasePackage>> = vec![]; - let mut removable_packages: Vec<Box<BasePackage>> = vec![]; + let mut installed_packages: Vec<Box<dyn BasePackage>> = vec![]; + let mut removable_packages: Vec<Box<dyn BasePackage>> = vec![]; for literal in &literals { if installed_map.contains_key(&abs(*literal)) { installed_packages.push(pool.literal_to_package(*literal)); @@ -534,7 +534,7 @@ pub trait Rule: std::fmt::Display { let rule_text = if literals.len() == 1 { pool.literal_to_pretty_string(literals[0], &installed_map) } else { - let mut groups: IndexMap<String, Vec<Box<BasePackage>>> = IndexMap::new(); + let mut groups: IndexMap<String, Vec<Box<dyn BasePackage>>> = IndexMap::new(); for literal in &literals { let package = pool.literal_to_package(*literal); let group = if installed_map.contains_key(&package.id) { @@ -624,12 +624,12 @@ pub trait Rule: std::fmt::Display { fn format_packages_unique( &self, pool: &Pool, - literals_or_packages: Vec<Box<BasePackage>>, + literals_or_packages: Vec<Box<dyn BasePackage>>, is_verbose: bool, constraint: Option<&dyn ConstraintInterface>, use_removed_version_group: bool, ) -> String { - let mut packages: Vec<Box<BasePackage>> = vec![]; + let mut packages: Vec<Box<dyn BasePackage>> = vec![]; for package in literals_or_packages { // PHP: \is_object($package) ? $package : $pool->literalToPackage($package); // In Rust we already have BasePackage, so no conversion needed. @@ -654,7 +654,7 @@ pub trait Rule: std::fmt::Display { constraint: Option<&dyn ConstraintInterface>, use_removed_version_group: bool, ) -> String { - let mut packages: Vec<Box<BasePackage>> = vec![]; + let mut packages: Vec<Box<dyn BasePackage>> = vec![]; for literal in literals { packages.push(pool.literal_to_package(*literal).clone_box()); } @@ -667,7 +667,10 @@ pub trait Rule: std::fmt::Display { ) } - fn deduplicate_default_branch_alias(&self, package: Box<BasePackage>) -> Box<BasePackage> { + fn deduplicate_default_branch_alias( + &self, + package: Box<dyn BasePackage>, + ) -> Box<dyn BasePackage> { if let Some(alias_pkg) = (package.as_any() as &dyn Any).downcast_ref::<AliasPackage>() { if alias_pkg.get_pretty_version() == VersionParser::DEFAULT_BRANCH_ALIAS { return alias_pkg.get_alias_of().clone_box(); diff --git a/crates/shirabe/src/dependency_resolver/rule_set.rs b/crates/shirabe/src/dependency_resolver/rule_set.rs index 4fc7928..8d33abf 100644 --- a/crates/shirabe/src/dependency_resolver/rule_set.rs +++ b/crates/shirabe/src/dependency_resolver/rule_set.rs @@ -11,10 +11,10 @@ use crate::repository::repository_set::RepositorySet; #[derive(Debug)] pub struct RuleSet { - pub rule_by_id: IndexMap<i64, Rule>, - pub(crate) rules: IndexMap<i64, Vec<Rule>>, + pub rule_by_id: IndexMap<i64, Box<dyn Rule>>, + pub(crate) rules: IndexMap<i64, Vec<Box<dyn Rule>>>, pub(crate) next_rule_id: i64, - pub(crate) rules_by_hash: IndexMap<String, Vec<Rule>>, + pub(crate) rules_by_hash: IndexMap<String, Vec<Box<dyn Rule>>>, } impl RuleSet { @@ -47,7 +47,7 @@ impl RuleSet { Self::types().into_keys().collect() } - pub fn add(&mut self, rule: Rule, r#type: i64) -> anyhow::Result<()> { + pub fn add(&mut self, rule: Box<dyn Rule>, r#type: i64) -> anyhow::Result<()> { let types = Self::types(); if !types.contains_key(&r#type) { return Err(OutOfBoundsException { @@ -88,11 +88,11 @@ impl RuleSet { self.next_rule_id } - pub fn rule_by_id(&self, id: i64) -> &Rule { - &self.rule_by_id[&id] + pub fn rule_by_id(&self, id: i64) -> &dyn Rule { + &*self.rule_by_id[&id] } - pub fn get_rules(&self) -> &IndexMap<i64, Vec<Rule>> { + pub fn get_rules(&self) -> &IndexMap<i64, Vec<Box<dyn Rule>>> { &self.rules } diff --git a/crates/shirabe/src/dependency_resolver/rule_set_generator.rs b/crates/shirabe/src/dependency_resolver/rule_set_generator.rs index 9c803d6..fb74a70 100644 --- a/crates/shirabe/src/dependency_resolver/rule_set_generator.rs +++ b/crates/shirabe/src/dependency_resolver/rule_set_generator.rs @@ -118,7 +118,7 @@ impl RuleSetGenerator { packages: &[Box<dyn PackageInterface>], reason: i64, reason_data: PhpMixed, - ) -> Rule { + ) -> Box<dyn Rule> { let literals: Vec<i64> = packages.iter().map(|p| -p.get_id()).collect(); if literals.len() == 2 { @@ -140,7 +140,7 @@ impl RuleSetGenerator { /// /// To be able to directly pass in the result of one of the rule creation /// methods null is allowed which will not insert a rule. - fn add_rule(&mut self, r#type: i64, new_rule: Option<Rule>) { + fn add_rule(&mut self, r#type: i64, new_rule: Option<Box<dyn Rule>>) { if let Some(rule) = new_rule { self.rules.add(rule, r#type).ok(); } diff --git a/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs b/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs index f66a277..259b510 100644 --- a/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs +++ b/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs @@ -6,7 +6,7 @@ use indexmap::IndexMap; /// Implements PHP \Iterator over a grouped rule set. #[derive(Debug)] pub struct RuleSetIterator { - pub(crate) rules: IndexMap<i64, Vec<Rule>>, + pub(crate) rules: IndexMap<i64, Vec<Box<dyn Rule>>>, pub(crate) types: Vec<i64>, pub(crate) current_offset: i64, pub(crate) current_type: i64, @@ -14,7 +14,7 @@ pub struct RuleSetIterator { } impl RuleSetIterator { - pub fn new(rules: IndexMap<i64, Vec<Rule>>) -> Self { + pub fn new(rules: IndexMap<i64, Vec<Box<dyn Rule>>>) -> Self { let mut types: Vec<i64> = rules.keys().copied().collect(); types.sort(); let mut iter = Self { @@ -28,8 +28,8 @@ impl RuleSetIterator { iter } - pub fn current(&self) -> &Rule { - &self.rules[&self.current_type][self.current_offset as usize] + pub fn current(&self) -> &dyn Rule { + &*self.rules[&self.current_type][self.current_offset as usize] } pub fn key(&self) -> i64 { diff --git a/crates/shirabe/src/dependency_resolver/solver.rs b/crates/shirabe/src/dependency_resolver/solver.rs index 388cccd..d5f4ccd 100644 --- a/crates/shirabe/src/dependency_resolver/solver.rs +++ b/crates/shirabe/src/dependency_resolver/solver.rs @@ -37,13 +37,13 @@ pub struct Solver { pub(crate) watch_graph: RuleWatchGraph, pub(crate) decisions: Decisions, - pub(crate) fixed_map: IndexMap<i64, Box<BasePackage>>, + pub(crate) fixed_map: IndexMap<i64, Box<dyn BasePackage>>, pub(crate) propagate_index: i64, /// Pairs of `(literals, level)` — PHP indexes into these with the BRANCH_* constants. pub(crate) branches: Vec<(Vec<i64>, i64)>, pub(crate) problems: Vec<Problem>, - pub(crate) learned_pool: Vec<Vec<Rule>>, + pub(crate) learned_pool: Vec<Vec<Box<dyn Rule>>>, pub(crate) learned_why: IndexMap<String, i64>, pub test_flag_learned_positive_literal: bool, @@ -292,7 +292,7 @@ impl Solver { /// If we find unit rules we make new decisions based on them /// /// Returns a `Rule` on conflict, otherwise `None`. - fn propagate(&mut self, level: i64) -> Option<Rule> { + fn propagate(&mut self, level: i64) -> Option<Box<dyn Rule>> { while self.decisions.valid_offset(self.propagate_index) { let decision = self .decisions @@ -349,7 +349,12 @@ impl Solver { /// rule (always unit) and re-propagate. /// /// returns the new solver level or 0 if unsolvable - fn set_propagate_learn(&mut self, level: i64, literal: i64, rule: Rule) -> anyhow::Result<i64> { + fn set_propagate_learn( + &mut self, + level: i64, + literal: i64, + rule: Box<dyn Rule>, + ) -> anyhow::Result<i64> { let mut level = level + 1; self.decisions.decide(literal, level, rule); @@ -401,7 +406,7 @@ impl Solver { &mut self, level: i64, decision_queue: Vec<i64>, - rule: Rule, + rule: Box<dyn Rule>, ) -> anyhow::Result<i64> { // choose best package to install from decisionQueue let mut literals = self.policy.select_preferred_packages( @@ -420,7 +425,11 @@ impl Solver { self.set_propagate_learn(level, selected_literal, rule) } - fn analyze(&mut self, level: i64, rule: Rule) -> anyhow::Result<(i64, i64, GenericRule, i64)> { + fn analyze( + &mut self, + level: i64, + rule: Box<dyn Rule>, + ) -> anyhow::Result<(i64, i64, GenericRule, i64)> { let analyzed_rule = rule.clone(); let mut rule = rule; let mut rule_level = 1_i64; @@ -591,7 +600,7 @@ impl Solver { fn analyze_unsolvable_rule( &self, problem: &mut Problem, - conflict_rule: &Rule, + conflict_rule: &dyn Rule, rule_seen: &mut IndexMap<String, bool>, ) { let why = spl_object_hash(conflict_rule); @@ -619,7 +628,7 @@ impl Solver { problem.add_rule(conflict_rule.clone()); } - fn analyze_unsolvable(&mut self, conflict_rule: &Rule) { + fn analyze_unsolvable(&mut self, conflict_rule: &dyn Rule) { let mut problem = Problem::new(); problem.add_rule(conflict_rule.clone()); diff --git a/crates/shirabe/src/dependency_resolver/solver_problems_exception.rs b/crates/shirabe/src/dependency_resolver/solver_problems_exception.rs index ddc8746..d739991 100644 --- a/crates/shirabe/src/dependency_resolver/solver_problems_exception.rs +++ b/crates/shirabe/src/dependency_resolver/solver_problems_exception.rs @@ -13,13 +13,13 @@ use crate::util::ini_helper::IniHelper; pub struct SolverProblemsException { inner: RuntimeException, pub(crate) problems: Vec<Problem>, - pub(crate) learned_pool: Vec<Vec<Rule>>, + pub(crate) learned_pool: Vec<Vec<Box<dyn Rule>>>, } impl SolverProblemsException { pub const ERROR_DEPENDENCY_RESOLUTION_FAILED: i64 = 2; - pub fn new(problems: Vec<Problem>, learned_pool: Vec<Vec<Rule>>) -> Self { + pub fn new(problems: Vec<Problem>, learned_pool: Vec<Vec<Box<dyn Rule>>>) -> Self { let message = format!( "Failed resolving dependencies with {} problems, call getPrettyString to get formatted details", problems.len() @@ -143,7 +143,7 @@ impl SolverProblemsException { text } - fn get_extension_problems(&self, reason_sets: Vec<Vec<Rule>>) -> Vec<String> { + fn get_extension_problems(&self, reason_sets: Vec<Vec<Box<dyn Rule>>>) -> Vec<String> { let mut missing_extensions: indexmap::IndexMap<String, i64> = indexmap::IndexMap::new(); for reason_set in reason_sets { for rule in reason_set { diff --git a/crates/shirabe/src/package/alias_package.rs b/crates/shirabe/src/package/alias_package.rs index a427913..cd2e5f1 100644 --- a/crates/shirabe/src/package/alias_package.rs +++ b/crates/shirabe/src/package/alias_package.rs @@ -33,7 +33,7 @@ pub struct AliasPackage { pub(crate) has_self_version_requires: bool, /// @var BasePackage - pub(crate) alias_of: Box<BasePackage>, + pub(crate) alias_of: Box<dyn BasePackage>, /// @var Link[] pub(crate) requires: IndexMap<String, Link>, /// @var Link[] @@ -52,7 +52,7 @@ impl AliasPackage { /// @param BasePackage $aliasOf The package this package is an alias of /// @param string $version The version the alias must report /// @param string $prettyVersion The alias's non-normalized version - pub fn new(alias_of: Box<BasePackage>, version: String, pretty_version: String) -> Self { + pub fn new(alias_of: Box<dyn BasePackage>, version: String, pretty_version: String) -> Self { let inner = BasePackage::new(alias_of.get_name().to_string()); let stability = VersionParser::parse_stability(&version); @@ -111,7 +111,7 @@ impl AliasPackage { this } - pub fn get_alias_of(&self) -> &BasePackage { + pub fn get_alias_of(&self) -> &dyn BasePackage { &self.alias_of } diff --git a/crates/shirabe/src/package/loader/array_loader.rs b/crates/shirabe/src/package/loader/array_loader.rs index 72d9754..28e13af 100644 --- a/crates/shirabe/src/package/loader/array_loader.rs +++ b/crates/shirabe/src/package/loader/array_loader.rs @@ -51,7 +51,7 @@ impl LoaderInterface for ArrayLoader { &self, mut config: IndexMap<String, PhpMixed>, class: Option<String>, - ) -> Result<Box<BasePackage>> { + ) -> Result<Box<dyn BasePackage>> { let class = class.unwrap_or_else(|| "Composer\\Package\\CompletePackage".to_string()); if class != "Composer\\Package\\CompletePackage" @@ -104,8 +104,8 @@ impl ArrayLoader { pub fn load_packages( &self, versions: Vec<IndexMap<String, PhpMixed>>, - ) -> Result<Vec<Box<BasePackage>>> { - let mut packages: Vec<Box<BasePackage>> = vec![]; + ) -> Result<Vec<Box<dyn BasePackage>>> { + let mut packages: Vec<Box<dyn BasePackage>> = vec![]; let mut link_cache: IndexMap< String, IndexMap<String, IndexMap<String, IndexMap<String, (String, Link)>>>, @@ -226,7 +226,7 @@ impl ArrayLoader { &self, mut package: Box<CompletePackage>, config: &mut IndexMap<String, PhpMixed>, - ) -> Result<Box<BasePackage>> { + ) -> Result<Box<dyn BasePackage>> { // PHP: if (!$package instanceof CompletePackage) — true by construction in Rust // (create_object always returns Box<CompletePackage>); kept as a no-op for parity. let _ = LogicException { diff --git a/crates/shirabe/src/package/loader/json_loader.rs b/crates/shirabe/src/package/loader/json_loader.rs index 8f10995..978bc28 100644 --- a/crates/shirabe/src/package/loader/json_loader.rs +++ b/crates/shirabe/src/package/loader/json_loader.rs @@ -20,7 +20,7 @@ impl JsonLoader { Self { loader } } - pub fn load(&self, json: JsonLoaderInput) -> Result<Box<BasePackage>> { + pub fn load(&self, json: JsonLoaderInput) -> Result<Box<dyn BasePackage>> { let config = match json { JsonLoaderInput::File(json_file) => json_file.read()?, JsonLoaderInput::String(ref s) if Path::new(s).exists() => { diff --git a/crates/shirabe/src/package/loader/loader_interface.rs b/crates/shirabe/src/package/loader/loader_interface.rs index 530f1eb..f941f9a 100644 --- a/crates/shirabe/src/package/loader/loader_interface.rs +++ b/crates/shirabe/src/package/loader/loader_interface.rs @@ -9,5 +9,5 @@ pub trait LoaderInterface { &self, config: IndexMap<String, PhpMixed>, class: Option<String>, - ) -> anyhow::Result<Box<BasePackage>>; + ) -> anyhow::Result<Box<dyn BasePackage>>; } diff --git a/crates/shirabe/src/package/loader/validating_array_loader.rs b/crates/shirabe/src/package/loader/validating_array_loader.rs index c1be9f2..3ba9212 100644 --- a/crates/shirabe/src/package/loader/validating_array_loader.rs +++ b/crates/shirabe/src/package/loader/validating_array_loader.rs @@ -65,7 +65,7 @@ impl ValidatingArrayLoader { &mut self, config: IndexMap<String, Box<PhpMixed>>, class: &str, - ) -> anyhow::Result<Box<BasePackage>> { + ) -> anyhow::Result<Box<dyn BasePackage>> { self.errors = Vec::new(); self.warnings = Vec::new(); self.config = config.clone(); diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs index e370339..5950437 100644 --- a/crates/shirabe/src/package/locker.rs +++ b/crates/shirabe/src/package/locker.rs @@ -209,7 +209,7 @@ impl Locker { false }; if has_name { - let mut package_by_name: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut package_by_name: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); if let PhpMixed::List(list) = locked_packages { for info in list { if let PhpMixed::Array(m) = info.as_ref() { diff --git a/crates/shirabe/src/plugin/capability/command_provider.rs b/crates/shirabe/src/plugin/capability/command_provider.rs index adc0148..f96c9e9 100644 --- a/crates/shirabe/src/plugin/capability/command_provider.rs +++ b/crates/shirabe/src/plugin/capability/command_provider.rs @@ -5,5 +5,5 @@ use crate::command::base_command::BaseCommand; use crate::plugin::capability::capability::Capability; pub trait CommandProvider: Capability { - fn get_commands(&self) -> Vec<Box<BaseCommand>>; + fn get_commands(&self) -> Vec<Box<dyn BaseCommand>>; } diff --git a/crates/shirabe/src/plugin/pre_pool_create_event.rs b/crates/shirabe/src/plugin/pre_pool_create_event.rs index 7363b08..5d1a4e9 100644 --- a/crates/shirabe/src/plugin/pre_pool_create_event.rs +++ b/crates/shirabe/src/plugin/pre_pool_create_event.rs @@ -16,8 +16,8 @@ pub struct PrePoolCreateEvent { stability_flags: IndexMap<String, i64>, root_aliases: IndexMap<String, IndexMap<String, IndexMap<String, String>>>, root_references: IndexMap<String, String>, - packages: Vec<BasePackage>, - unacceptable_fixed_packages: Vec<BasePackage>, + packages: Vec<Box<dyn BasePackage>>, + unacceptable_fixed_packages: Vec<Box<dyn BasePackage>>, } impl PrePoolCreateEvent { @@ -30,8 +30,8 @@ impl PrePoolCreateEvent { stability_flags: IndexMap<String, i64>, root_aliases: IndexMap<String, IndexMap<String, IndexMap<String, String>>>, root_references: IndexMap<String, String>, - packages: Vec<BasePackage>, - unacceptable_fixed_packages: Vec<BasePackage>, + packages: Vec<Box<dyn BasePackage>>, + unacceptable_fixed_packages: Vec<Box<dyn BasePackage>>, ) -> Self { Self { inner: Event::new(name, vec![], IndexMap::new()), @@ -72,19 +72,19 @@ impl PrePoolCreateEvent { &self.root_references } - pub fn get_packages(&self) -> &Vec<BasePackage> { + pub fn get_packages(&self) -> &Vec<Box<dyn BasePackage>> { &self.packages } - pub fn get_unacceptable_fixed_packages(&self) -> &Vec<BasePackage> { + pub fn get_unacceptable_fixed_packages(&self) -> &Vec<Box<dyn BasePackage>> { &self.unacceptable_fixed_packages } - pub fn set_packages(&mut self, packages: Vec<BasePackage>) { + pub fn set_packages(&mut self, packages: Vec<Box<dyn BasePackage>>) { self.packages = packages; } - pub fn set_unacceptable_fixed_packages(&mut self, packages: Vec<BasePackage>) { + pub fn set_unacceptable_fixed_packages(&mut self, packages: Vec<Box<dyn BasePackage>>) { self.unacceptable_fixed_packages = packages; } } diff --git a/crates/shirabe/src/repository/array_repository.rs b/crates/shirabe/src/repository/array_repository.rs index 7bb7e81..5262b5e 100644 --- a/crates/shirabe/src/repository/array_repository.rs +++ b/crates/shirabe/src/repository/array_repository.rs @@ -31,10 +31,10 @@ use crate::repository::repository_interface::{ pub struct ArrayRepository { /// @var ?array<BasePackage> // TODO(phase-b): RefCell models PHP's lazy init via getPackages()/count() under &self - pub(crate) packages: RefCell<Option<Vec<Box<BasePackage>>>>, + pub(crate) packages: RefCell<Option<Vec<Box<dyn BasePackage>>>>, /// @var ?array<BasePackage> indexed by package unique name and used to cache hasPackage calls - pub(crate) package_map: RefCell<Option<IndexMap<String, Box<BasePackage>>>>, + pub(crate) package_map: RefCell<Option<IndexMap<String, Box<dyn BasePackage>>>>, } impl ArrayRepository { @@ -63,9 +63,9 @@ impl ArrayRepository { } .into()); } - // TODO(phase-b): convert Box<dyn PackageInterface> to Box<BasePackage> - let mut package: Box<BasePackage> = - todo!("downcast Box<dyn PackageInterface> to Box<BasePackage>"); + // TODO(phase-b): convert Box<dyn PackageInterface> to Box<dyn BasePackage> + let mut package: Box<dyn BasePackage> = + todo!("downcast Box<dyn PackageInterface> to Box<dyn BasePackage>"); if self.packages.borrow().is_none() { self.initialize(); @@ -73,7 +73,7 @@ impl ArrayRepository { // TODO(phase-b): pass a reference to self, not a clone package.set_repository(todo!("self as Box<dyn RepositoryInterface>"))?; - let aliased_package: Option<Box<BasePackage>> = + let aliased_package: Option<Box<dyn BasePackage>> = if let Some(alias) = (package.as_any() as &dyn Any).downcast_ref::<AliasPackage>() { Some(alias.get_alias_of().clone_box()) } else { @@ -97,10 +97,10 @@ impl ArrayRepository { /// @return AliasPackage|CompleteAliasPackage pub(crate) fn create_alias_package( &self, - mut package: Box<BasePackage>, + mut package: Box<dyn BasePackage>, alias: String, pretty_alias: String, - ) -> Box<BasePackage> { + ) -> Box<dyn BasePackage> { while let Some(alias_pkg) = (package.as_any() as &dyn Any).downcast_ref::<AliasPackage>() { package = alias_pkg.get_alias_of().clone_box(); } @@ -173,7 +173,7 @@ impl RepositoryInterface for ArrayRepository { ) -> LoadPackagesResult { let packages = self.get_packages(); - let mut result: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut result: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); let mut names_found: IndexMap<String, bool> = IndexMap::new(); for package in &packages { if package_name_map.contains_key(package.get_name()) { @@ -231,7 +231,7 @@ impl RepositoryInterface for ArrayRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option<Box<BasePackage>> { + ) -> Option<Box<dyn BasePackage>> { let name = strtolower(&name); let constraint: Box<dyn ConstraintInterface> = match constraint { @@ -259,7 +259,7 @@ impl RepositoryInterface for ArrayRepository { &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { // normalize name let name = strtolower(&name); let mut packages = vec![]; @@ -377,7 +377,7 @@ impl RepositoryInterface for ArrayRepository { fn has_package(&self, package: &dyn PackageInterface) -> bool { if self.package_map.borrow().is_none() { - let mut map: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut map: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); for repo_package in self.get_packages() { map.insert(repo_package.get_unique_name(), repo_package); } @@ -419,7 +419,7 @@ impl RepositoryInterface for ArrayRepository { result } - fn get_packages(&self) -> Vec<Box<BasePackage>> { + fn get_packages(&self) -> Vec<Box<dyn BasePackage>> { if self.packages.borrow().is_none() { self.initialize(); } diff --git a/crates/shirabe/src/repository/artifact_repository.rs b/crates/shirabe/src/repository/artifact_repository.rs index d869156..faef831 100644 --- a/crates/shirabe/src/repository/artifact_repository.rs +++ b/crates/shirabe/src/repository/artifact_repository.rs @@ -133,7 +133,10 @@ impl ArtifactRepository { Ok(()) } - fn get_composer_information(&self, file: &Path) -> anyhow::Result<Option<Box<BasePackage>>> { + fn get_composer_information( + &self, + file: &Path, + ) -> anyhow::Result<Option<Box<dyn BasePackage>>> { let mut json: Option<String> = None; let file_extension = file .extension() diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index ea73090..15ea084 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -119,21 +119,21 @@ pub struct ComposerRepository { #[derive(Debug)] pub enum FindPackageReturn { - Package(Box<BasePackage>), - Packages(Vec<Box<BasePackage>>), + Package(Box<dyn BasePackage>), + Packages(Vec<Box<dyn BasePackage>>), None, } #[derive(Debug)] pub struct LoadPackagesResult { pub names_found: Vec<String>, - pub packages: IndexMap<String, Box<BasePackage>>, + pub packages: IndexMap<String, Box<dyn BasePackage>>, } #[derive(Debug)] pub struct LoadAsyncPackagesResult { pub names_found: IndexMap<String, bool>, - pub packages: IndexMap<String, Box<BasePackage>>, + pub packages: IndexMap<String, Box<dyn BasePackage>>, } impl ConfigurableRepositoryInterface for ComposerRepository { @@ -326,7 +326,7 @@ impl ComposerRepository { &mut self, name: String, constraint: PhpMixed, - ) -> anyhow::Result<Option<Box<BasePackage>>> { + ) -> anyhow::Result<Option<Box<dyn BasePackage>>> { // this call initializes loadRootServerFile which is needed for the rest below to work let has_providers = self.has_providers()?; @@ -347,7 +347,7 @@ impl ComposerRepository { .map_or(false, |m| m.contains_key(&name)) { let packages = self.what_provides(&name, None, None, IndexMap::new())?; - let packages_vec: Vec<Box<BasePackage>> = packages.into_values().collect(); + let packages_vec: Vec<Box<dyn BasePackage>> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, Some(&*constraint), true) { FindPackageReturn::Package(p) => Some(p), @@ -376,7 +376,7 @@ impl ComposerRepository { if name == provider_name { let packages = self.what_provides(&provider_name, None, None, IndexMap::new())?; - let packages_vec: Vec<Box<BasePackage>> = packages.into_values().collect(); + let packages_vec: Vec<Box<dyn BasePackage>> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, Some(&*constraint), true) { FindPackageReturn::Package(p) => Some(p), @@ -397,7 +397,7 @@ impl ComposerRepository { &mut self, name: String, constraint: Option<PhpMixed>, - ) -> anyhow::Result<Vec<Box<BasePackage>>> { + ) -> anyhow::Result<Vec<Box<dyn BasePackage>>> { // this call initializes loadRootServerFile which is needed for the rest below to work let has_providers = self.has_providers()?; @@ -416,7 +416,7 @@ impl ComposerRepository { .map_or(false, |m| m.contains_key(&name)) { let packages = self.what_provides(&name, None, None, IndexMap::new())?; - let packages_vec: Vec<Box<BasePackage>> = packages.into_values().collect(); + let packages_vec: Vec<Box<dyn BasePackage>> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, constraint.as_deref(), false) { FindPackageReturn::Packages(v) => v, @@ -441,7 +441,7 @@ impl ComposerRepository { if name == provider_name { let packages = self.what_provides(&provider_name, None, None, IndexMap::new())?; - let packages_vec: Vec<Box<BasePackage>> = packages.into_values().collect(); + let packages_vec: Vec<Box<dyn BasePackage>> = packages.into_values().collect(); return Ok( match self.filter_packages(packages_vec, constraint.as_deref(), false) { FindPackageReturn::Packages(v) => v, @@ -459,7 +459,7 @@ impl ComposerRepository { fn filter_packages( &self, - packages: Vec<Box<BasePackage>>, + packages: Vec<Box<dyn BasePackage>>, constraint: Option<&dyn ConstraintInterface>, return_first_match: bool, ) -> FindPackageReturn { @@ -475,7 +475,7 @@ impl ComposerRepository { } let constraint = constraint.unwrap(); - let mut filtered_packages: Vec<Box<BasePackage>> = Vec::new(); + let mut filtered_packages: Vec<Box<dyn BasePackage>> = Vec::new(); for package in packages.into_iter() { let pkg_constraint = Constraint::new("==", package.get_version().to_string()); @@ -496,7 +496,7 @@ impl ComposerRepository { FindPackageReturn::Packages(filtered_packages) } - pub fn get_packages(&mut self) -> anyhow::Result<Vec<Box<BasePackage>>> { + pub fn get_packages(&mut self) -> anyhow::Result<Vec<Box<dyn BasePackage>>> { let has_providers = self.has_providers()?; if self.lazy_providers_url.is_some() { @@ -723,13 +723,13 @@ impl ComposerRepository { ); } - let mut packages: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut packages: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); let mut names_found: IndexMap<String, bool> = IndexMap::new(); if has_providers || self.has_partial_packages()? { let names: Vec<String> = package_name_map.keys().cloned().collect(); for name in names { - let mut matches: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut matches: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); // if a repo has no providers but only partial packages and the partial packages are missing // then we don't want to call whatProvides as it would try to load from the providers and fail @@ -1383,7 +1383,7 @@ impl ComposerRepository { acceptable_stabilities: Option<&IndexMap<String, i64>>, stability_flags: Option<&IndexMap<String, i64>>, already_loaded: IndexMap<String, IndexMap<String, Box<dyn PackageInterface>>>, - ) -> anyhow::Result<IndexMap<String, Box<BasePackage>>> { + ) -> anyhow::Result<IndexMap<String, Box<dyn BasePackage>>> { let mut packages_source: Option<String> = None; let packages: IndexMap<String, PhpMixed>; let loading_partial_package: bool; @@ -1600,7 +1600,7 @@ impl ComposerRepository { loading_partial_package = true; } - let mut result: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut result: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); let mut versions_to_load: IndexMap<String, IndexMap<String, PhpMixed>> = IndexMap::new(); let packages_inner = packages .get("packages") @@ -1749,7 +1749,7 @@ impl ComposerRepository { } /// Adds a new package to the repository - pub fn add_package(&mut self, mut package: Box<BasePackage>) { + pub fn add_package(&mut self, mut package: Box<dyn BasePackage>) { // configurePackageTransportOptions(*package); self.configure_package_transport_options(&mut *package); self.inner.add_package(package); @@ -1765,7 +1765,7 @@ impl ComposerRepository { ) -> anyhow::Result<LoadAsyncPackagesResult> { self.load_root_server_file(None)?; - let mut packages: IndexMap<String, Box<BasePackage>> = IndexMap::new(); + let mut packages: IndexMap<String, Box<dyn BasePackage>> = IndexMap::new(); let mut names_found: IndexMap<String, bool> = IndexMap::new(); let mut promises: Vec<Box<dyn PromiseInterface>> = Vec::new(); @@ -1952,7 +1952,7 @@ impl ComposerRepository { } } - let loaded_packages: Vec<Box<BasePackage>> = + let loaded_packages: Vec<Box<dyn BasePackage>> = ComposerRepository::create_packages_static( versions_to_load, packages_source, @@ -2708,13 +2708,13 @@ impl ComposerRepository { &mut self, packages: Vec<IndexMap<String, PhpMixed>>, source: Option<String>, - ) -> anyhow::Result<Vec<Box<BasePackage>>> { + ) -> anyhow::Result<Vec<Box<dyn BasePackage>>> { if packages.is_empty() { return Ok(vec![]); } let mut packages = packages; - let result = (|| -> anyhow::Result<Vec<Box<BasePackage>>> { + let result = (|| -> anyhow::Result<Vec<Box<dyn BasePackage>>> { for data in packages.iter_mut() { if !data.contains_key("notification-url") { data.insert( @@ -2729,7 +2729,7 @@ impl ComposerRepository { let package_instances = self.loader.load_packages(packages.clone())?; - let mut results: Vec<Box<BasePackage>> = Vec::new(); + let mut results: Vec<Box<dyn BasePackage>> = Vec::new(); for mut package in package_instances.into_iter() { if let Some(src_type) = package.get_source_type() { if let Some(mirrors) = @@ -2768,7 +2768,7 @@ impl ComposerRepository { fn create_packages_static( packages: Vec<IndexMap<String, PhpMixed>>, _source: Option<String>, - ) -> anyhow::Result<Vec<Box<BasePackage>>> { + ) -> anyhow::Result<Vec<Box<dyn BasePackage>>> { if packages.is_empty() { return Ok(vec![]); } @@ -3448,7 +3448,7 @@ fn clone_root_data(rd: &RootData) -> RootData { } } -fn dyn_clone_box(_pkg: &BasePackage) -> Box<BasePackage> { +fn dyn_clone_box(_pkg: &dyn BasePackage) -> Box<dyn BasePackage> { todo!() } diff --git a/crates/shirabe/src/repository/composite_repository.rs b/crates/shirabe/src/repository/composite_repository.rs index e34a5f8..4914538 100644 --- a/crates/shirabe/src/repository/composite_repository.rs +++ b/crates/shirabe/src/repository/composite_repository.rs @@ -80,7 +80,7 @@ impl RepositoryInterface for CompositeRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option<Box<BasePackage>> { + ) -> Option<Box<dyn BasePackage>> { for repository in &self.repositories { let package = repository.find_package(name.clone(), constraint.clone()); if package.is_some() { @@ -94,7 +94,7 @@ impl RepositoryInterface for CompositeRepository { &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { let mut packages = vec![]; for repository in &self.repositories { packages.extend(repository.find_packages(name.clone(), constraint.clone())); @@ -102,7 +102,7 @@ impl RepositoryInterface for CompositeRepository { packages } - fn get_packages(&self) -> Vec<Box<BasePackage>> { + fn get_packages(&self) -> Vec<Box<dyn BasePackage>> { let mut packages = vec![]; for repository in &self.repositories { packages.extend(repository.get_packages()); diff --git a/crates/shirabe/src/repository/filter_repository.rs b/crates/shirabe/src/repository/filter_repository.rs index eeb1306..ce6a38a 100644 --- a/crates/shirabe/src/repository/filter_repository.rs +++ b/crates/shirabe/src/repository/filter_repository.rs @@ -161,7 +161,7 @@ impl RepositoryInterface for FilterRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option<Box<BasePackage>> { + ) -> Option<Box<dyn BasePackage>> { if !self.is_allowed(&name) { return None; } @@ -173,7 +173,7 @@ impl RepositoryInterface for FilterRepository { &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { if !self.is_allowed(&name) { return Vec::new(); } @@ -222,7 +222,7 @@ impl RepositoryInterface for FilterRepository { result } - fn get_packages(&self) -> Vec<Box<BasePackage>> { + fn get_packages(&self) -> Vec<Box<dyn BasePackage>> { let mut result = Vec::new(); for package in self.repo.get_packages() { if self.is_allowed(package.get_name()) { diff --git a/crates/shirabe/src/repository/installed_repository.rs b/crates/shirabe/src/repository/installed_repository.rs index bb56c94..3b6563d 100644 --- a/crates/shirabe/src/repository/installed_repository.rs +++ b/crates/shirabe/src/repository/installed_repository.rs @@ -26,7 +26,7 @@ pub enum NeedleInput { } pub struct DependentsEntry( - pub Box<BasePackage>, + pub Box<dyn BasePackage>, pub Link, pub Option<Vec<DependentsEntry>>, ); @@ -51,7 +51,7 @@ impl InstalledRepository { &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { let name = name.to_lowercase(); let constraint: Option<Box<dyn ConstraintInterface>> = match constraint { @@ -117,7 +117,7 @@ impl InstalledRepository { let mut packages_found = packages_found.unwrap_or_else(|| needles.clone()); - let mut root_package: Option<Box<BasePackage>> = None; + let mut root_package: Option<Box<dyn BasePackage>> = None; for package in self.inner.get_packages() { if package.as_any().is::<dyn RootPackageInterface>() { root_package = Some(package); @@ -422,7 +422,7 @@ impl RepositoryInterface for InstalledRepository { &self, name: String, constraint: FindPackageConstraint, - ) -> Option<Box<BasePackage>> { + ) -> Option<Box<dyn BasePackage>> { self.inner.find_package(name, constraint) } @@ -430,11 +430,11 @@ impl RepositoryInterface for InstalledRepository { &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { self.inner.find_packages(name, constraint) } - fn get_packages(&self) -> Vec<Box<BasePackage>> { + fn get_packages(&self) -> Vec<Box<dyn BasePackage>> { self.inner.get_packages() } diff --git a/crates/shirabe/src/repository/repository_interface.rs b/crates/shirabe/src/repository/repository_interface.rs index 777d3f6..c321908 100644 --- a/crates/shirabe/src/repository/repository_interface.rs +++ b/crates/shirabe/src/repository/repository_interface.rs @@ -14,7 +14,7 @@ pub enum FindPackageConstraint { pub struct LoadPackagesResult { pub names_found: Vec<String>, - pub packages: Vec<Box<BasePackage>>, + pub packages: Vec<Box<dyn BasePackage>>, } pub enum AbandonedInfo { @@ -46,15 +46,15 @@ pub trait RepositoryInterface: Countable { &self, name: String, constraint: FindPackageConstraint, - ) -> Option<Box<BasePackage>>; + ) -> Option<Box<dyn BasePackage>>; fn find_packages( &self, name: String, constraint: Option<FindPackageConstraint>, - ) -> Vec<Box<BasePackage>>; + ) -> Vec<Box<dyn BasePackage>>; - fn get_packages(&self) -> Vec<Box<BasePackage>>; + fn get_packages(&self) -> Vec<Box<dyn BasePackage>>; fn load_packages( &self, diff --git a/crates/shirabe/src/repository/repository_set.rs b/crates/shirabe/src/repository/repository_set.rs index e25bd29..6985a18 100644 --- a/crates/shirabe/src/repository/repository_set.rs +++ b/crates/shirabe/src/repository/repository_set.rs @@ -211,11 +211,11 @@ impl RepositorySet { name: &str, constraint: Option<Box<dyn ConstraintInterface>>, flags: i64, - ) -> Vec<Box<BasePackage>> { + ) -> Vec<Box<dyn BasePackage>> { let ignore_stability = (flags & Self::ALLOW_UNACCEPTABLE_STABILITIES) != 0; let load_from_all_repos = (flags & Self::ALLOW_SHADOWED_REPOSITORIES) != 0; - let mut packages: Vec<Vec<Box<BasePackage>>> = vec![]; + let mut packages: Vec<Vec<Box<dyn BasePackage>>> = vec![]; if load_from_all_repos { for repository in &self.repositories { // PHP: $repository->findPackages($name, $constraint) ?: [] @@ -262,7 +262,7 @@ impl RepositorySet { } // PHP: $candidates = $packages ? array_merge(...$packages) : []; - let candidates: Vec<Box<BasePackage>> = if !packages.is_empty() { + let candidates: Vec<Box<dyn BasePackage>> = if !packages.is_empty() { packages.into_iter().flatten().collect() } else { vec![] @@ -273,7 +273,7 @@ impl RepositorySet { return candidates; } - let mut result: Vec<Box<BasePackage>> = vec![]; + let mut result: Vec<Box<dyn BasePackage>> = vec![]; for candidate in candidates { if self.is_package_acceptable(&candidate.get_names(true), candidate.get_stability()) { result.push(candidate); @@ -518,7 +518,7 @@ impl RepositorySet { self.locked = true; - let mut packages: Vec<Box<BasePackage>> = vec![]; + let mut packages: Vec<Box<dyn BasePackage>> = vec![]; for repository in &self.repositories { for mut package in repository.get_packages() { let name = package.get_name().to_string(); @@ -532,7 +532,7 @@ impl RepositorySet { { package = alias_pkg.get_alias_of().clone_box(); } - let alias_package: Box<BasePackage> = if (package.as_any() as &dyn Any) + let alias_package: Box<dyn BasePackage> = if (package.as_any() as &dyn Any) .downcast_ref::<CompletePackage>() .is_some() { diff --git a/crates/shirabe/src/repository/vcs_repository.rs b/crates/shirabe/src/repository/vcs_repository.rs index 9499790..4374130 100644 --- a/crates/shirabe/src/repository/vcs_repository.rs +++ b/crates/shirabe/src/repository/vcs_repository.rs @@ -973,7 +973,7 @@ impl VcsRepository { enum CachedPackageResult { None, Missing, - Package(Box<BasePackage>), + Package(Box<dyn BasePackage>), } #[derive(Debug)] |
