aarch64_std/sync/
poison.rs

1use core::convert::Infallible;
2
3/// An enumeration of possible errors associated with a [`TryLockResult`] which
4/// can occur while trying to acquire a lock, from the [`try_lock`] method on a
5/// [`Mutex`] or the [`try_read`] and [`try_write`] methods on an [`RwLock`].
6///
7/// [`try_lock`]: crate::sync::Mutex::try_lock
8/// [`try_read`]: crate::sync::RwLock::try_read
9/// [`try_write`]: crate::sync::RwLock::try_write
10/// [`Mutex`]: crate::sync::Mutex
11/// [`RwLock`]: crate::sync::RwLock
12pub enum TryLockError {
13    /// The lock could not be acquired at this time because the operation would
14    /// otherwise block.
15    WouldBlock,
16}
17
18#[cfg(feature = "alloc")]
19impl alloc::fmt::Debug for TryLockError {
20    fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
21        match *self {
22            TryLockError::WouldBlock => "WouldBlock".fmt(f),
23        }
24    }
25}
26
27#[cfg(feature = "alloc")]
28impl alloc::fmt::Display for TryLockError {
29    fn fmt(&self, f: &mut alloc::fmt::Formatter<'_>) -> alloc::fmt::Result {
30        match *self {
31            TryLockError::WouldBlock => "try_lock failed because the operation would block",
32        }
33        .fmt(f)
34    }
35}
36
37pub type LockResult<Guard> = Result<Guard, Infallible>;
38
39/// A type alias for the result of a nonblocking locking method.
40///
41/// For more information, see [`LockResult`]. A `TryLockResult` doesn't
42/// necessarily hold the associated guard in the [`Err`] type as the lock might not
43/// have been acquired for other reasons.
44pub type TryLockResult<Guard> = Result<Guard, TryLockError>;