option_lock/
error.rs

1use core::fmt::{self, Display, Formatter};
2
3/// Error returned by failing try-lock operations
4#[derive(Debug, PartialEq, Eq)]
5pub enum OptionLockError {
6    /// The fill state of the lock did not match the requirement
7    FillState,
8    /// The lock could not be acquired
9    Unavailable,
10}
11
12impl Display for OptionLockError {
13    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
14        f.write_str(match self {
15            Self::FillState => "OptionLockError(FillState)",
16            Self::Unavailable => "OptionLockError(Unavailable)",
17        })
18    }
19}
20
21#[cfg(feature = "std")]
22impl ::std::error::Error for OptionLockError {}
23
24/// Error returned by failing mutex lock operations
25#[derive(Debug, PartialEq, Eq)]
26pub enum MutexLockError {
27    /// The lock value was removed
28    Poisoned,
29    /// The lock could not be acquired
30    Unavailable,
31}
32
33impl Display for MutexLockError {
34    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
35        f.write_str(match self {
36            Self::Poisoned => "MutexLockError(Poisoned)",
37            Self::Unavailable => "MutexLockError(Unavailable)",
38        })
39    }
40}
41
42#[cfg(feature = "std")]
43impl ::std::error::Error for MutexLockError {}
44
45/// Error returned when a lock has been poisoned
46#[derive(Debug, PartialEq, Eq)]
47pub struct PoisonError;
48
49impl Display for PoisonError {
50    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
51        f.write_str("PoisonError")
52    }
53}
54
55#[cfg(feature = "std")]
56impl ::std::error::Error for PoisonError {}