Skip to main content

composer_semver/
stability.rs

1//! Composer stability flags.
2//!
3//! Order from least to most stable: `dev < alpha < beta < RC < stable`.
4//! Lower = less stable; `Ord` is wired so `Stable > Dev`.
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub enum Stability {
8    Dev,
9    Alpha,
10    Beta,
11    Rc,
12    Stable,
13}
14
15impl Stability {
16    /// Parse a Composer stability keyword. Returns `None` for unknown strings.
17    /// Matches the keywords accepted by `composer.json`'s `minimum-stability`.
18    pub fn parse(s: &str) -> Option<Self> {
19        match s.to_ascii_lowercase().as_str() {
20            "dev" => Some(Self::Dev),
21            "alpha" => Some(Self::Alpha),
22            "beta" => Some(Self::Beta),
23            "rc" => Some(Self::Rc),
24            "stable" => Some(Self::Stable),
25            _ => None,
26        }
27    }
28
29    pub fn as_str(self) -> &'static str {
30        match self {
31            Self::Dev => "dev",
32            Self::Alpha => "alpha",
33            Self::Beta => "beta",
34            Self::Rc => "RC",
35            Self::Stable => "stable",
36        }
37    }
38}