std/sync/
nonpoison.rs

1//! Non-poisoning synchronous locks.
2//!
3//! The difference from the locks in the [`poison`] module is that the locks in this module will not
4//! become poisoned when a thread panics while holding a guard.
5//!
6//! [`poison`]: super::poison
7
8use crate::fmt;
9
10/// A type alias for the result of a nonblocking locking method.
11#[unstable(feature = "sync_nonpoison", issue = "134645")]
12pub type TryLockResult<Guard> = Result<Guard, WouldBlock>;
13
14/// A lock could not be acquired at this time because the operation would otherwise block.
15#[unstable(feature = "sync_nonpoison", issue = "134645")]
16pub struct WouldBlock;
17
18#[unstable(feature = "sync_nonpoison", issue = "134645")]
19impl fmt::Debug for WouldBlock {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        "WouldBlock".fmt(f)
22    }
23}
24
25#[unstable(feature = "sync_nonpoison", issue = "134645")]
26impl fmt::Display for WouldBlock {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        "try_lock failed because the operation would block".fmt(f)
29    }
30}
31
32#[unstable(feature = "mapped_lock_guards", issue = "117108")]
33pub use self::mutex::MappedMutexGuard;
34#[unstable(feature = "nonpoison_mutex", issue = "134645")]
35pub use self::mutex::{Mutex, MutexGuard};
36
37mod mutex;