1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
12pub enum CacheMode {
13 #[default]
17 Default,
18
19 KeepHot,
24
25 MakeCold,
30
31 EvictLn,
36
37 EvictBin,
42
43 Unchanged,
48}
49
50impl CacheMode {
51 pub fn evicts_ln(&self) -> bool {
53 matches!(self, CacheMode::EvictLn | CacheMode::EvictBin)
54 }
55
56 pub fn evicts_bin(&self) -> bool {
58 matches!(self, CacheMode::EvictBin)
59 }
60
61 pub fn keeps_hot(&self) -> bool {
63 matches!(self, CacheMode::KeepHot)
64 }
65
66 pub fn modifies_cache(&self) -> bool {
68 !matches!(self, CacheMode::Unchanged)
69 }
70}
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 #[test]
77 fn test_default() {
78 assert_eq!(CacheMode::default(), CacheMode::Default);
79 }
80
81 #[test]
82 fn test_evicts_ln() {
83 assert!(CacheMode::EvictLn.evicts_ln());
84 assert!(CacheMode::EvictBin.evicts_ln());
85 assert!(!CacheMode::Default.evicts_ln());
86 assert!(!CacheMode::KeepHot.evicts_ln());
87 }
88
89 #[test]
90 fn test_evicts_bin() {
91 assert!(CacheMode::EvictBin.evicts_bin());
92 assert!(!CacheMode::EvictLn.evicts_bin());
93 assert!(!CacheMode::Default.evicts_bin());
94 }
95
96 #[test]
97 fn test_keeps_hot() {
98 assert!(CacheMode::KeepHot.keeps_hot());
99 assert!(!CacheMode::Default.keeps_hot());
100 assert!(!CacheMode::EvictLn.keeps_hot());
101 }
102
103 #[test]
104 fn test_modifies_cache() {
105 assert!(CacheMode::Default.modifies_cache());
106 assert!(CacheMode::KeepHot.modifies_cache());
107 assert!(!CacheMode::Unchanged.modifies_cache());
108 }
109
110 #[test]
111 fn test_equality() {
112 assert_eq!(CacheMode::Default, CacheMode::Default);
113 assert_ne!(CacheMode::Default, CacheMode::KeepHot);
114 }
115
116 #[test]
117 fn test_clone() {
118 let mode1 = CacheMode::EvictBin;
119 let mode2 = mode1;
120 assert_eq!(mode1, mode2);
121 }
122
123 #[test]
124 fn test_copy() {
125 let mode1 = CacheMode::MakeCold;
126 let mode2 = mode1;
127 assert_eq!(mode1, mode2);
128 }
129
130 #[test]
131 fn test_debug() {
132 let mode = CacheMode::KeepHot;
133 let debug = format!("{:?}", mode);
134 assert_eq!(debug, "KeepHot");
135 }
136}