faf_rust_sdk/binary/
priority.rs1pub const PRIORITY_CRITICAL: u8 = 255;
8
9pub const PRIORITY_HIGH: u8 = 200;
11
12pub const PRIORITY_MEDIUM: u8 = 128;
14
15pub const PRIORITY_LOW: u8 = 64;
17
18pub const PRIORITY_OPTIONAL: u8 = 0;
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
23pub struct Priority(pub u8);
24
25impl Priority {
26 pub const fn new(value: u8) -> Self {
28 Self(value)
29 }
30
31 pub const fn critical() -> Self {
33 Self(PRIORITY_CRITICAL)
34 }
35
36 pub const fn high() -> Self {
38 Self(PRIORITY_HIGH)
39 }
40
41 pub const fn medium() -> Self {
43 Self(PRIORITY_MEDIUM)
44 }
45
46 pub const fn low() -> Self {
48 Self(PRIORITY_LOW)
49 }
50
51 pub const fn optional() -> Self {
53 Self(PRIORITY_OPTIONAL)
54 }
55
56 pub const fn value(&self) -> u8 {
58 self.0
59 }
60
61 pub const fn is_critical(&self) -> bool {
63 self.0 == PRIORITY_CRITICAL
64 }
65
66 pub const fn is_high(&self) -> bool {
68 self.0 >= PRIORITY_HIGH
69 }
70
71 pub const fn is_optional(&self) -> bool {
73 self.0 == PRIORITY_OPTIONAL
74 }
75
76 pub const fn level_name(&self) -> &'static str {
78 match self.0 {
79 255 => "CRITICAL",
80 200..=254 => "HIGH",
81 128..=199 => "MEDIUM",
82 1..=127 => "LOW",
83 0 => "OPTIONAL",
84 }
85 }
86}
87
88impl Default for Priority {
89 fn default() -> Self {
90 Self::medium()
91 }
92}
93
94impl From<u8> for Priority {
95 fn from(value: u8) -> Self {
96 Self(value)
97 }
98}
99
100impl From<Priority> for u8 {
101 fn from(priority: Priority) -> Self {
102 priority.0
103 }
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn test_priority_constants() {
112 assert_eq!(PRIORITY_CRITICAL, 255);
113 assert_eq!(PRIORITY_HIGH, 200);
114 assert_eq!(PRIORITY_MEDIUM, 128);
115 assert_eq!(PRIORITY_LOW, 64);
116 assert_eq!(PRIORITY_OPTIONAL, 0);
117 }
118
119 #[test]
120 fn test_priority_constructors() {
121 assert_eq!(Priority::critical().value(), 255);
122 assert_eq!(Priority::high().value(), 200);
123 assert_eq!(Priority::medium().value(), 128);
124 assert_eq!(Priority::low().value(), 64);
125 assert_eq!(Priority::optional().value(), 0);
126 }
127
128 #[test]
129 fn test_priority_ordering() {
130 assert!(Priority::critical() > Priority::high());
131 assert!(Priority::high() > Priority::medium());
132 assert!(Priority::medium() > Priority::low());
133 assert!(Priority::low() > Priority::optional());
134 }
135
136 #[test]
137 fn test_is_critical() {
138 assert!(Priority::critical().is_critical());
139 assert!(!Priority::high().is_critical());
140 }
141
142 #[test]
143 fn test_is_high() {
144 assert!(Priority::critical().is_high());
145 assert!(Priority::high().is_high());
146 assert!(!Priority::medium().is_high());
147 }
148
149 #[test]
150 fn test_is_optional() {
151 assert!(Priority::optional().is_optional());
152 assert!(!Priority::low().is_optional());
153 }
154
155 #[test]
156 fn test_level_names() {
157 assert_eq!(Priority::critical().level_name(), "CRITICAL");
158 assert_eq!(Priority::high().level_name(), "HIGH");
159 assert_eq!(Priority::medium().level_name(), "MEDIUM");
160 assert_eq!(Priority::low().level_name(), "LOW");
161 assert_eq!(Priority::optional().level_name(), "OPTIONAL");
162 }
163
164 #[test]
165 fn test_default_is_medium() {
166 assert_eq!(Priority::default(), Priority::medium());
167 }
168}