pub trait ICacheEntryValidityChecker<K, V: ?Sized>: Send + Sync {
fn check_is_value_still_valid(&self, key: &K, value: &V, entry_creation_timestamp: i64)
-> bool;
}
#[cfg(test)]
mod tests {
use super::ICacheEntryValidityChecker;
struct BoundaryChecker;
impl ICacheEntryValidityChecker<String, String> for BoundaryChecker {
fn check_is_value_still_valid(
&self,
key: &String,
value: &String,
entry_creation_timestamp: i64,
) -> bool {
key == "key" && value == "value" && entry_creation_timestamp == i64::MIN
}
}
#[test]
fn supports_dynamic_checkers_and_preserves_all_arguments() {
let checker: &dyn ICacheEntryValidityChecker<String, String> = &BoundaryChecker;
assert!(checker.check_is_value_still_valid(
&"key".to_owned(),
&"value".to_owned(),
i64::MIN
));
assert!(!checker.check_is_value_still_valid(
&"other".to_owned(),
&"value".to_owned(),
i64::MAX
));
}
}