Skip to main content

spatialrust_platform/
lts.rs

1//! Long-term support policy and calendar helpers.
2
3/// Support window for one major line.
4#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct SupportWindow {
6    /// Major version tag, e.g. `1.x`.
7    pub major_line: String,
8    /// Months of active support.
9    pub active_months: u32,
10    /// Months of security-only support after active ends.
11    pub security_months: u32,
12}
13
14impl SupportWindow {
15    /// Total supported months (active + security-only).
16    #[must_use]
17    pub fn total_months(&self) -> u32 {
18        self.active_months.saturating_add(self.security_months)
19    }
20}
21
22/// Long-term support policy.
23#[derive(Clone, Debug, Default, PartialEq, Eq)]
24pub struct LtsPolicy {
25    windows: Vec<SupportWindow>,
26}
27
28impl LtsPolicy {
29    /// Creates an empty policy.
30    #[must_use]
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// Declares a support window.
36    pub fn declare(&mut self, window: SupportWindow) {
37        self.windows.push(window);
38    }
39
40    /// Returns declared windows.
41    #[must_use]
42    pub fn windows(&self) -> &[SupportWindow] {
43        &self.windows
44    }
45
46    /// Looks up a major line window.
47    #[must_use]
48    pub fn window_for(&self, major_line: &str) -> Option<&SupportWindow> {
49        self.windows.iter().find(|window| window.major_line == major_line)
50    }
51
52    /// Default SpatialRust 1.x policy used by Epic 100.
53    #[must_use]
54    pub fn spatialrust_v1() -> Self {
55        let mut policy = Self::new();
56        policy.declare(SupportWindow {
57            major_line: "1.x".into(),
58            active_months: 18,
59            security_months: 6,
60        });
61        policy
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::LtsPolicy;
68
69    #[test]
70    fn v1_policy_declares_window() {
71        let policy = LtsPolicy::spatialrust_v1();
72        assert_eq!(policy.windows().len(), 1);
73        assert_eq!(policy.window_for("1.x").unwrap().total_months(), 24);
74    }
75}