Skip to main content

intentional_core/
model.rs

1// ---
2// relationships:
3//   implements: intent-driven-polyglot-release
4// ---
5
6//! Shared release domain values.
7
8use serde::{Deserialize, Serialize};
9use std::fmt;
10use std::str::FromStr;
11
12/// Semantic version change declared by an intent.
13#[derive(
14    Debug, Clone, Copy, Default, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash,
15)]
16#[serde(rename_all = "lowercase")]
17pub enum Bump {
18    /// No change.
19    #[default]
20    None,
21    /// Backwards-compatible bug fix.
22    Patch,
23    /// Backwards-compatible feature.
24    Minor,
25    /// Breaking change.
26    Major,
27}
28
29impl fmt::Display for Bump {
30    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
31        formatter.write_str(match self {
32            Self::None => "none",
33            Self::Patch => "patch",
34            Self::Minor => "minor",
35            Self::Major => "major",
36        })
37    }
38}
39
40impl FromStr for Bump {
41    type Err = String;
42
43    fn from_str(value: &str) -> std::result::Result<Self, Self::Err> {
44        match value {
45            "patch" => Ok(Self::Patch),
46            "minor" => Ok(Self::Minor),
47            "major" => Ok(Self::Major),
48            _ => Err(format!("expected major, minor, or patch; got {value}")),
49        }
50    }
51}
52
53/// How a version projection is materialized.
54#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
55#[serde(rename_all = "lowercase")]
56pub enum ProjectionMode {
57    /// Version is written for a source-controlled release commit.
58    Committed,
59    /// Version is written only for build-time stamping.
60    Injected,
61    /// No manifest version is written.
62    None,
63}
64
65/// Manifest or generic format adapter used by a projection.
66#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq, Hash)]
67#[serde(rename_all = "lowercase")]
68pub enum Adapter {
69    /// npm `package.json`.
70    Npm,
71    /// Cargo `Cargo.toml`.
72    Cargo,
73    /// Dart/Flutter `pubspec.yaml`.
74    Pub,
75    /// PEP 621 `pyproject.toml`.
76    Python,
77    /// MSBuild project file.
78    Msbuild,
79    /// Go module file.
80    Go,
81    /// Generic JSON file.
82    Json,
83    /// Generic TOML file.
84    Toml,
85    /// Generic YAML file.
86    Yaml,
87}
88
89impl Adapter {
90    /// Whether the adapter requires an explicit pointer.
91    pub fn requires_pointer(self) -> bool {
92        matches!(self, Self::Json | Self::Toml | Self::Yaml)
93    }
94
95    /// Whether the projection participates in dependency range rewriting.
96    pub fn ecosystem(self) -> Option<&'static str> {
97        match self {
98            Self::Npm => Some("npm"),
99            Self::Cargo => Some("cargo"),
100            Self::Pub => Some("pub"),
101            Self::Python => Some("python"),
102            Self::Msbuild => Some("msbuild"),
103            Self::Go => Some("go"),
104            Self::Json | Self::Toml | Self::Yaml => None,
105        }
106    }
107}