qubit_lock/lock/try_lock_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # Try Lock Error
10//!
11//! Error type for non-blocking lock acquisition.
12//!
13//! # Author
14//!
15//! Haixing Hu
16
17use std::fmt;
18
19/// Non-blocking lock acquisition error.
20///
21/// This error type is used by `try_read` and `try_write` to distinguish
22/// immediate lock contention from poisoned lock states. The
23/// [`Self::Poisoned`] variant is returned only by lock implementations that
24/// support poisoning.
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum TryLockError {
27 /// The lock could not be acquired immediately because another guard is active.
28 WouldBlock,
29 /// The lock implementation reports a poisoned state.
30 Poisoned,
31}
32
33impl fmt::Display for TryLockError {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 match self {
36 Self::WouldBlock => f.write_str("lock acquisition would block"),
37 Self::Poisoned => f.write_str("lock is poisoned"),
38 }
39 }
40}
41
42impl std::error::Error for TryLockError {}