From dbdecaf5a1c54a876b7ee0153d58dd39b1080f97 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 23 May 2026 23:14:52 +0900 Subject: 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) --- .../src/command/check_platform_reqs_command.rs | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'crates/shirabe/src/command/check_platform_reqs_command.rs') diff --git a/crates/shirabe/src/command/check_platform_reqs_command.rs b/crates/shirabe/src/command/check_platform_reqs_command.rs index 83770be..74ecfc3 100644 --- a/crates/shirabe/src/command/check_platform_reqs_command.rs +++ b/crates/shirabe/src/command/check_platform_reqs_command.rs @@ -5,8 +5,8 @@ use indexmap::IndexMap; use shirabe_external_packages::symfony::component::console::input::InputInterface; use shirabe_external_packages::symfony::component::console::output::OutputInterface; use shirabe_php_shim::{PhpMixed, strip_tags}; -use shirabe_semver::constraint::Constraint; -use shirabe_semver::constraint::ConstraintInterface; +use shirabe_semver::constraint::AnyConstraint; +use shirabe_semver::constraint::SimpleConstraint; use crate::command::{BaseCommand, BaseCommandData, HasBaseCommandData}; use crate::console::input::InputOption; @@ -147,22 +147,23 @@ impl CheckPlatformReqsCommand { if !candidates.is_empty() { let mut req_results: Vec = vec![]; 'candidates: for candidate in &candidates { - let candidate_constraint: Option> = + let candidate_constraint: Option = if candidate.get_name() == require { - let mut c = Constraint::new("=", candidate.get_version()); - c.set_pretty_string(Some( - candidate.get_pretty_version().to_string(), - )); - Some(Box::new(c)) + let c = SimpleConstraint::new( + "=".to_string(), + candidate.get_version().to_string(), + Some(candidate.get_pretty_version().to_string()), + ); + Some(c.into()) } else { - let mut found: Option> = None; + let mut found: Option = None; for (_, link) in candidate .get_provides() .iter() .chain(candidate.get_replaces().iter()) { if link.get_target() == require { - found = Some(link.get_constraint().clone_box()); + found = Some(link.get_constraint().clone()); break; } } @@ -175,7 +176,7 @@ impl CheckPlatformReqsCommand { }; for link in links { - if !link.get_constraint().matches(&*candidate_constraint) { + if !link.get_constraint().matches(&candidate_constraint) { req_results.push(CheckResult { platform_package: if candidate.get_name() == require { candidate.get_pretty_name().to_string() -- cgit v1.3.1