aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-16 23:34:06 +0900
committernsfisis <nsfisis@gmail.com>2026-05-16 23:34:06 +0900
commit2a885fa094922860b4a49c272816fc6b7e48d07f (patch)
treec8ef1dcc568e1708641bdeeb3988db977843de45 /crates/shirabe-semver/src
parent8ffb2bd26c0ba5f238b14cd11f7ef3ddaef840b0 (diff)
downloadphp-shirabe-2a885fa094922860b4a49c272816fc6b7e48d07f.tar.gz
php-shirabe-2a885fa094922860b4a49c272816fc6b7e48d07f.tar.zst
php-shirabe-2a885fa094922860b4a49c272816fc6b7e48d07f.zip
feat(port): port Interval.php
Diffstat (limited to 'crates/shirabe-semver/src')
-rw-r--r--crates/shirabe-semver/src/interval.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/crates/shirabe-semver/src/interval.rs b/crates/shirabe-semver/src/interval.rs
index 8c729dc..aa1bea8 100644
--- a/crates/shirabe-semver/src/interval.rs
+++ b/crates/shirabe-semver/src/interval.rs
@@ -1 +1,63 @@
//! ref: composer/vendor/composer/semver/src/Interval.php
+
+use std::sync::OnceLock;
+
+use crate::constraint::constraint::Constraint;
+
+#[derive(Debug)]
+pub struct DevConstraintSet {
+ pub names: Vec<String>,
+ pub exclude: bool,
+}
+
+#[derive(Debug)]
+pub struct Interval {
+ start: Constraint,
+ end: Constraint,
+}
+
+impl Interval {
+ pub fn new(start: Constraint, end: Constraint) -> Self {
+ Self { start, end }
+ }
+
+ pub fn get_start(&self) -> &Constraint {
+ &self.start
+ }
+
+ pub fn get_end(&self) -> &Constraint {
+ &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 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 any() -> Self {
+ Self::new(
+ Self::from_zero().clone(),
+ Self::until_positive_infinity().clone(),
+ )
+ }
+
+ pub fn any_dev() -> DevConstraintSet {
+ DevConstraintSet {
+ names: vec![],
+ exclude: true,
+ }
+ }
+
+ pub fn no_dev() -> DevConstraintSet {
+ DevConstraintSet {
+ names: vec![],
+ exclude: false,
+ }
+ }
+}