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) --- crates/shirabe-semver/src/interval.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'crates/shirabe-semver/src/interval.rs') diff --git a/crates/shirabe-semver/src/interval.rs b/crates/shirabe-semver/src/interval.rs index b1f3010..7f27514 100644 --- a/crates/shirabe-semver/src/interval.rs +++ b/crates/shirabe-semver/src/interval.rs @@ -1,8 +1,6 @@ //! ref: composer/vendor/composer/semver/src/Interval.php -use std::sync::OnceLock; - -use crate::constraint::Constraint; +use crate::constraint::SimpleConstraint; #[derive(Debug, Clone)] pub struct DevConstraintSet { @@ -12,32 +10,29 @@ pub struct DevConstraintSet { #[derive(Debug, Clone)] pub struct Interval { - start: Constraint, - end: Constraint, + start: SimpleConstraint, + end: SimpleConstraint, } impl Interval { - pub fn new(start: Constraint, end: Constraint) -> Self { + pub fn new(start: SimpleConstraint, end: SimpleConstraint) -> Self { Self { start, end } } - pub fn get_start(&self) -> &Constraint { + pub fn get_start(&self) -> &SimpleConstraint { &self.start } - pub fn get_end(&self) -> &Constraint { + pub fn get_end(&self) -> &SimpleConstraint { &self.end } - pub fn from_zero() -> &'static Constraint { - static ZERO: OnceLock = OnceLock::new(); - ZERO.get_or_init(|| Constraint::new(">=".to_string(), "0.0.0.0-dev".to_string())) + pub fn from_zero() -> SimpleConstraint { + SimpleConstraint::new(">=".to_string(), "0.0.0.0-dev".to_string(), None) } - pub fn until_positive_infinity() -> &'static Constraint { - static POSITIVE_INFINITY: OnceLock = OnceLock::new(); - POSITIVE_INFINITY - .get_or_init(|| Constraint::new("<".to_string(), format!("{}.0.0.0", i64::MAX))) + pub fn until_positive_infinity() -> SimpleConstraint { + SimpleConstraint::new("<".to_string(), format!("{}.0.0.0", i64::MAX), None) } pub fn any() -> Self { -- cgit v1.3.1