diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-23 23:14:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-23 23:15:14 +0900 |
| commit | dbdecaf5a1c54a876b7ee0153d58dd39b1080f97 (patch) | |
| tree | f13f2ced03c803dcbc42a5672458b3cb19ff0f30 /crates/shirabe/src/package/version/version_selector.rs | |
| parent | f5b987a00712211b7ce56300851182bda904e97b (diff) | |
| download | php-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.tar.gz php-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.tar.zst php-shirabe-dbdecaf5a1c54a876b7ee0153d58dd39b1080f97.zip | |
refactor(semver): change ConstraintInterface to a closed enum
Replace the dyn ConstraintInterface trait objects with an AnyConstraint
enum closing over its four implementors (Simple, Multi, MatchAll,
MatchNone), mirroring the earlier Rule enum conversion. Rename
constraint.rs to simple_constraint.rs to match the renamed Constraint
type.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/package/version/version_selector.rs')
| -rw-r--r-- | crates/shirabe/src/package/version/version_selector.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crates/shirabe/src/package/version/version_selector.rs b/crates/shirabe/src/package/version/version_selector.rs index 832f64c..3bd0191 100644 --- a/crates/shirabe/src/package/version/version_selector.rs +++ b/crates/shirabe/src/package/version/version_selector.rs @@ -8,8 +8,8 @@ use shirabe_external_packages::composer::pcre::Preg; use shirabe_php_shim::{ PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION, strtolower, version_compare, }; -use shirabe_semver::constraint::Constraint; -use shirabe_semver::constraint::ConstraintInterface; +use shirabe_semver::constraint::AnyConstraint; +use shirabe_semver::constraint::SimpleConstraint; use crate::filter::platform_requirement_filter::IgnoreAllPlatformRequirementFilter; use crate::filter::platform_requirement_filter::IgnoreListPlatformRequirementFilter; @@ -29,7 +29,7 @@ use crate::repository::RepositorySet; #[derive(Debug)] pub struct VersionSelector { repository_set: RepositorySet, - platform_constraints: IndexMap<String, Vec<Box<dyn ConstraintInterface>>>, + platform_constraints: IndexMap<String, Vec<AnyConstraint>>, parser: Option<VersionParser>, } @@ -38,16 +38,19 @@ impl VersionSelector { repository_set: RepositorySet, platform_repo: Option<&crate::repository::PlatformRepository>, ) -> anyhow::Result<Self> { - let mut platform_constraints: IndexMap<String, Vec<Box<dyn ConstraintInterface>>> = - IndexMap::new(); + let mut platform_constraints: IndexMap<String, Vec<AnyConstraint>> = IndexMap::new(); if let Some(platform_repo) = platform_repo { for package in <PlatformRepository as RepositoryInterface>::get_packages(platform_repo) { - let constraint = Constraint::new("==", package.get_version()); + let constraint = SimpleConstraint::new( + "==".to_string(), + package.get_version().to_string(), + None, + ); platform_constraints .entry(package.get_name().to_string()) .or_default() - .push(Box::new(constraint)); + .push(constraint.into()); } } Ok(Self { @@ -90,7 +93,7 @@ impl VersionSelector { }; let mut candidates = self.repository_set.find_packages( &strtolower(package_name), - constraint.as_ref().map(|c| c.clone_box()), + constraint.as_ref().map(|c| c.clone()), repo_set_flags, ); @@ -142,7 +145,7 @@ impl VersionSelector { let reason; if let Some(provided_constraints) = self.platform_constraints.get(name) { for provided_constraint in provided_constraints { - if link.get_constraint().matches(provided_constraint.as_ref()) { + if link.get_constraint().matches(provided_constraint) { continue 'reqs; } let list_filter_opt = platform_requirement_filter @@ -154,10 +157,10 @@ impl VersionSelector { if list_filter.is_upper_bound_ignored(name) { let filtered_constraint = list_filter.filter_constraint( name, - link.get_constraint().clone_box(), + link.get_constraint().clone(), false, )?; - if filtered_constraint.matches(provided_constraint.as_ref()) { + if filtered_constraint.matches(provided_constraint) { continue 'reqs; } } |
