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-semver/src/compiling_matcher.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-semver/src/compiling_matcher.rs')
| -rw-r--r-- | crates/shirabe-semver/src/compiling_matcher.rs | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/shirabe-semver/src/compiling_matcher.rs b/crates/shirabe-semver/src/compiling_matcher.rs index 737647f..d7e203e 100644 --- a/crates/shirabe-semver/src/compiling_matcher.rs +++ b/crates/shirabe-semver/src/compiling_matcher.rs @@ -5,8 +5,8 @@ use std::sync::OnceLock; use indexmap::IndexMap; -use crate::constraint::Constraint; -use crate::constraint::ConstraintInterface; +use crate::constraint::AnyConstraint; +use crate::constraint::SimpleConstraint; static COMPILED_CHECKER_CACHE: OnceLock< Mutex<IndexMap<String, Box<dyn Fn(String, bool) -> bool + Send + Sync>>>, @@ -16,12 +16,12 @@ static RESULT_CACHE: OnceLock<Mutex<IndexMap<String, bool>>> = OnceLock::new(); // Rust does not support eval(), so the compiled checker path is always disabled. // The COMPILED_CHECKER_CACHE is retained structurally but never populated. static TRANS_OP_INT: &[(i64, &str)] = &[ - (Constraint::OP_EQ, Constraint::STR_OP_EQ), - (Constraint::OP_LT, Constraint::STR_OP_LT), - (Constraint::OP_LE, Constraint::STR_OP_LE), - (Constraint::OP_GT, Constraint::STR_OP_GT), - (Constraint::OP_GE, Constraint::STR_OP_GE), - (Constraint::OP_NE, Constraint::STR_OP_NE), + (SimpleConstraint::OP_EQ, SimpleConstraint::STR_OP_EQ), + (SimpleConstraint::OP_LT, SimpleConstraint::STR_OP_LT), + (SimpleConstraint::OP_LE, SimpleConstraint::STR_OP_LE), + (SimpleConstraint::OP_GT, SimpleConstraint::STR_OP_GT), + (SimpleConstraint::OP_GE, SimpleConstraint::STR_OP_GE), + (SimpleConstraint::OP_NE, SimpleConstraint::STR_OP_NE), ]; pub struct CompilingMatcher; @@ -41,8 +41,8 @@ impl CompilingMatcher { Self::compiled_checker_cache().lock().unwrap().clear(); } - pub fn r#match(constraint: &dyn ConstraintInterface, operator: i64, version: String) -> bool { - let result_cache_key = format!("{}{};{}", operator, constraint.__to_string(), version); + pub fn r#match(constraint: &AnyConstraint, operator: i64, version: String) -> bool { + let result_cache_key = format!("{}{};{}", operator, constraint.to_string(), version); { let cache = Self::result_cache().lock().unwrap(); @@ -56,7 +56,8 @@ impl CompilingMatcher { .find(|(op, _)| *op == operator) .map(|(_, s)| *s) .expect("unknown operator"); - let result = constraint.matches(&Constraint::new(trans_op.to_string(), version)); + let result = + constraint.matches(&SimpleConstraint::new(trans_op.to_string(), version, None).into()); Self::result_cache() .lock() |
