aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver/src/constraint/match_all_constraint.rs
blob: 8d4e87057b0fe6f10d2e9cf761cef3125e8fc97b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! ref: composer/vendor/composer/semver/src/Constraint/MatchAllConstraint.php

use crate::constraint::Bound;

#[derive(Debug, Clone, Default)]
pub struct MatchAllConstraint {
    pub(crate) pretty_string: Option<String>,
}

impl MatchAllConstraint {
    pub fn new(pretty_string: Option<String>) -> Self {
        Self { pretty_string }
    }

    pub fn compile(&self, _other_operator: i64) -> String {
        "true".to_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()
    }

    pub fn get_upper_bound(&self) -> Bound {
        Bound::positive_infinity()
    }

    pub fn get_lower_bound(&self) -> Bound {
        Bound::zero()
    }
}

impl std::fmt::Display for MatchAllConstraint {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "*")
    }
}