spatialrust_platform/
lts.rs1#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct SupportWindow {
6 pub major_line: String,
8 pub active_months: u32,
10 pub security_months: u32,
12}
13
14impl SupportWindow {
15 #[must_use]
17 pub fn total_months(&self) -> u32 {
18 self.active_months.saturating_add(self.security_months)
19 }
20}
21
22#[derive(Clone, Debug, Default, PartialEq, Eq)]
24pub struct LtsPolicy {
25 windows: Vec<SupportWindow>,
26}
27
28impl LtsPolicy {
29 #[must_use]
31 pub fn new() -> Self {
32 Self::default()
33 }
34
35 pub fn declare(&mut self, window: SupportWindow) {
37 self.windows.push(window);
38 }
39
40 #[must_use]
42 pub fn windows(&self) -> &[SupportWindow] {
43 &self.windows
44 }
45
46 #[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 #[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}