use crate::msg::MsgType;
#[must_use]
pub fn memcache_storage(ty: MsgType) -> bool {
matches!(
ty,
MsgType::ReqMcSet
| MsgType::ReqMcCas
| MsgType::ReqMcAdd
| MsgType::ReqMcReplace
| MsgType::ReqMcAppend
| MsgType::ReqMcPrepend
)
}
#[must_use]
pub fn memcache_cas(ty: MsgType) -> bool {
matches!(ty, MsgType::ReqMcCas)
}
#[must_use]
pub fn memcache_retrieval(ty: MsgType) -> bool {
matches!(ty, MsgType::ReqMcGet | MsgType::ReqMcGets)
}
#[must_use]
pub fn memcache_arithmetic(ty: MsgType) -> bool {
matches!(ty, MsgType::ReqMcIncr | MsgType::ReqMcDecr)
}
#[must_use]
pub fn memcache_delete(ty: MsgType) -> bool {
matches!(ty, MsgType::ReqMcDelete)
}
#[must_use]
pub fn memcache_touch(ty: MsgType) -> bool {
matches!(ty, MsgType::ReqMcTouch)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn classification_partition_is_disjoint() {
for ty in [
MsgType::ReqMcGet,
MsgType::ReqMcGets,
MsgType::ReqMcSet,
MsgType::ReqMcAdd,
MsgType::ReqMcReplace,
MsgType::ReqMcAppend,
MsgType::ReqMcPrepend,
MsgType::ReqMcCas,
MsgType::ReqMcDelete,
MsgType::ReqMcIncr,
MsgType::ReqMcDecr,
MsgType::ReqMcTouch,
MsgType::ReqMcQuit,
] {
let storage = memcache_storage(ty);
let retrieval = memcache_retrieval(ty);
let arithmetic = memcache_arithmetic(ty);
let delete = memcache_delete(ty);
let touch = memcache_touch(ty);
let count = [storage, retrieval, arithmetic, delete, touch]
.iter()
.filter(|x| **x)
.count();
assert!(count <= 1, "{ty:?} matched {count} categories");
}
}
}