1#[derive(Debug, Clone, Copy, Eq, PartialEq)]
2pub enum ChangeType {
3 Alpha,
4 Beta,
5 None,
6}
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq)]
9pub struct SemVerChangeID {
10 pub r#type: ChangeType,
11 pub id: i32,
12}
13
14unsafe impl Send for ChangeType {}
15unsafe impl Sync for ChangeType {}
16
17unsafe impl Send for SemVerChangeID {}
18unsafe impl Sync for SemVerChangeID {}
19
20impl ChangeType {
21 pub fn to_string(&self) -> String {
22 return match self.clone() {
23 ChangeType::Alpha => String::from("alpha"),
24 ChangeType::Beta => String::from("beta"),
25 ChangeType::None => String::from(""),
26 };
27 }
28}
29
30impl SemVerChangeID {
31 pub fn gt(&self, other: SemVerChangeID) -> bool {
32 if other.r#type == ChangeType::None {
33 return match self.r#type {
34 ChangeType::None => self.id > other.id,
35 _ => false,
36 };
37 } else if other.r#type == ChangeType::Alpha {
38 return match self.r#type {
39 ChangeType::Alpha => self.id > other.id,
40 _ => true,
41 };
42 } else if other.r#type == ChangeType::Beta {
43 return match self.r#type {
44 ChangeType::Beta => self.id > other.id,
45 ChangeType::Alpha => false,
46 ChangeType::None => true,
47 };
48 }
49
50 panic!("Unknown change type!");
51 }
52
53 pub fn lt(&self, other: SemVerChangeID) -> bool {
54 if other.r#type == ChangeType::None {
55 return match self.r#type {
56 ChangeType::None => self.id < other.id,
57 _ => true,
58 };
59 } else if other.r#type == ChangeType::Alpha {
60 return match self.r#type {
61 ChangeType::Alpha => self.id < other.id,
62 _ => false,
63 };
64 } else if other.r#type == ChangeType::Beta {
65 return match self.r#type {
66 ChangeType::Beta => self.id < other.id,
67 ChangeType::Alpha => true,
68 ChangeType::None => false,
69 };
70 }
71
72 panic!("Unknown change type!");
73 }
74
75 pub fn eq(&self, other: SemVerChangeID) -> bool {
76 return other.r#type == self.r#type && other.id == self.id;
77 }
78
79 pub fn to_string(&self) -> String {
80 if self.r#type == ChangeType::None {
81 return self.id.to_string();
82 }
83
84 return format!("{}.{}", self.r#type.to_string(), self.id.to_string());
85 }
86}