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/interval.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/interval.rs')
| -rw-r--r-- | crates/shirabe-semver/src/interval.rs | 25 |
1 files changed, 10 insertions, 15 deletions
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<Constraint> = 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<Constraint> = 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 { |
