agentguard_policy/
version.rs1use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
12#[serde(transparent)]
13pub struct PolicyVersion(u64);
14
15impl PolicyVersion {
16 pub fn new(v: u64) -> Self {
17 Self(v)
18 }
19
20 pub fn as_u64(&self) -> u64 {
21 self.0
22 }
23
24 pub fn next(self) -> Self {
26 Self(self.0.saturating_add(1))
27 }
28}
29
30impl fmt::Display for PolicyVersion {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "v{}", self.0)
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn ordering() {
42 assert!(PolicyVersion::new(2) > PolicyVersion::new(1));
43 assert_eq!(PolicyVersion::new(1).next(), PolicyVersion::new(2));
44 }
45
46 #[test]
47 fn display() {
48 assert_eq!(PolicyVersion::new(42).to_string(), "v42");
49 }
50}