#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LockGrantType {
New,
WaitNew,
Promotion,
WaitPromotion,
Existing,
Denied,
WaitRestart,
NoneNeeded,
}
impl LockGrantType {
#[inline]
pub fn is_granted(self) -> bool {
matches!(
self,
LockGrantType::New
| LockGrantType::Promotion
| LockGrantType::Existing
)
}
#[inline]
pub fn must_wait(self) -> bool {
matches!(
self,
LockGrantType::WaitNew
| LockGrantType::WaitPromotion
| LockGrantType::WaitRestart
)
}
#[inline]
pub fn is_promotion(self) -> bool {
matches!(self, LockGrantType::Promotion | LockGrantType::WaitPromotion)
}
#[inline]
pub fn is_denied(self) -> bool {
self == LockGrantType::Denied
}
#[inline]
pub fn is_restart(self) -> bool {
self == LockGrantType::WaitRestart
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_granted() {
assert!(LockGrantType::New.is_granted());
assert!(LockGrantType::Promotion.is_granted());
assert!(LockGrantType::Existing.is_granted());
assert!(!LockGrantType::WaitNew.is_granted());
assert!(!LockGrantType::WaitPromotion.is_granted());
assert!(!LockGrantType::Denied.is_granted());
assert!(!LockGrantType::WaitRestart.is_granted());
assert!(!LockGrantType::NoneNeeded.is_granted());
}
#[test]
fn test_must_wait() {
assert!(LockGrantType::WaitNew.must_wait());
assert!(LockGrantType::WaitPromotion.must_wait());
assert!(LockGrantType::WaitRestart.must_wait());
assert!(!LockGrantType::New.must_wait());
assert!(!LockGrantType::Promotion.must_wait());
assert!(!LockGrantType::Existing.must_wait());
assert!(!LockGrantType::Denied.must_wait());
assert!(!LockGrantType::NoneNeeded.must_wait());
}
#[test]
fn test_is_promotion() {
assert!(LockGrantType::Promotion.is_promotion());
assert!(LockGrantType::WaitPromotion.is_promotion());
assert!(!LockGrantType::New.is_promotion());
assert!(!LockGrantType::WaitNew.is_promotion());
assert!(!LockGrantType::Existing.is_promotion());
}
#[test]
fn test_is_denied() {
assert!(LockGrantType::Denied.is_denied());
assert!(!LockGrantType::New.is_denied());
assert!(!LockGrantType::WaitNew.is_denied());
assert!(!LockGrantType::Existing.is_denied());
}
#[test]
fn test_is_restart() {
assert!(LockGrantType::WaitRestart.is_restart());
assert!(!LockGrantType::WaitNew.is_restart());
assert!(!LockGrantType::WaitPromotion.is_restart());
assert!(!LockGrantType::New.is_restart());
}
}