aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver/src/constraint/match_none_constraint.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-23 23:14:52 +0900
committernsfisis <nsfisis@gmail.com>2026-05-23 23:15:14 +0900
commitdbdecaf5a1c54a876b7ee0153d58dd39b1080f97 (patch)
treef13f2ced03c803dcbc42a5672458b3cb19ff0f30 /crates/shirabe-semver/src/constraint/match_none_constraint.rs
parentf5b987a00712211b7ce56300851182bda904e97b (diff)
downloadphp-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/constraint/match_none_constraint.rs')
-rw-r--r--crates/shirabe-semver/src/constraint/match_none_constraint.rs41
1 files changed, 14 insertions, 27 deletions
diff --git a/crates/shirabe-semver/src/constraint/match_none_constraint.rs b/crates/shirabe-semver/src/constraint/match_none_constraint.rs
index 587058a..08cb319 100644
--- a/crates/shirabe-semver/src/constraint/match_none_constraint.rs
+++ b/crates/shirabe-semver/src/constraint/match_none_constraint.rs
@@ -1,54 +1,41 @@
//! ref: composer/vendor/composer/semver/src/Constraint/MatchNoneConstraint.php
use crate::constraint::Bound;
-use crate::constraint::ConstraintInterface;
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct MatchNoneConstraint {
pub(crate) pretty_string: Option<String>,
}
-impl ConstraintInterface for MatchNoneConstraint {
- fn matches(&self, _provider: &dyn ConstraintInterface) -> bool {
- false
+impl MatchNoneConstraint {
+ pub fn new(pretty_string: Option<String>) -> Self {
+ Self { pretty_string }
}
- fn compile(&self, _other_operator: i64) -> String {
+ pub fn compile(&self, _other_operator: i64) -> String {
"false".to_string()
}
- fn set_pretty_string(&mut self, pretty_string: Option<String>) {
- self.pretty_string = pretty_string;
- }
-
- fn get_pretty_string(&self) -> String {
+ pub fn get_pretty_string(&self) -> String {
if let Some(ref s) = self.pretty_string
&& !s.is_empty()
{
return s.clone();
}
- self.__to_string()
+ self.to_string()
}
- fn __to_string(&self) -> String {
- "[]".to_string()
- }
-
- fn clone_box(&self) -> Box<dyn ConstraintInterface> {
- Box::new(MatchNoneConstraint {
- pretty_string: self.pretty_string.clone(),
- })
- }
-
- fn as_any(&self) -> &dyn std::any::Any {
- self
+ pub fn get_upper_bound(&self) -> Bound {
+ Bound::new("0.0.0.0-dev".to_string(), false)
}
- fn get_upper_bound(&self) -> Bound {
+ pub fn get_lower_bound(&self) -> Bound {
Bound::new("0.0.0.0-dev".to_string(), false)
}
+}
- fn get_lower_bound(&self) -> Bound {
- Bound::new("0.0.0.0-dev".to_string(), false)
+impl std::fmt::Display for MatchNoneConstraint {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f, "[]")
}
}