use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum LockError {
Conflict,
NotHeld,
}
impl fmt::Display for LockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Conflict => f.write_str("lock request conflicts with an existing lock"),
Self::NotHeld => f.write_str("no lock held for this transaction and resource"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for LockError {}
#[cfg(test)]
mod tests {
use super::LockError;
#[cfg(feature = "std")]
#[test]
fn test_display_messages_are_distinct_and_nonempty() {
let conflict = LockError::Conflict.to_string();
let not_held = LockError::NotHeld.to_string();
assert!(!conflict.is_empty());
assert!(!not_held.is_empty());
assert_ne!(conflict, not_held);
}
#[test]
fn test_variants_compare_equal_to_themselves() {
assert_eq!(LockError::Conflict, LockError::Conflict);
assert_ne!(LockError::Conflict, LockError::NotHeld);
}
}