diff options
| author | Mica White <botahamec@gmail.com> | 2024-07-17 16:37:21 -0400 |
|---|---|---|
| committer | Mica White <botahamec@gmail.com> | 2024-07-21 12:55:32 -0400 |
| commit | bd64ff98530ea5f92ce528009d65203f0f6676fe (patch) | |
| tree | 27e6c6a2153e3a9c4ecf4087f473b89a01b25033 /src/poisonable/error.rs | |
| parent | 32f972a26a0066291873445088718deec3ed4233 (diff) | |
Create Poisonable API
Diffstat (limited to 'src/poisonable/error.rs')
| -rw-r--r-- | src/poisonable/error.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/poisonable/error.rs b/src/poisonable/error.rs new file mode 100644 index 0000000..98a167c --- /dev/null +++ b/src/poisonable/error.rs @@ -0,0 +1,47 @@ +use core::fmt; +use std::error::Error; + +use super::{PoisonError, PoisonGuard, TryLockPoisonableError}; + +impl<Guard> fmt::Debug for PoisonError<Guard> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("PoisonError").finish_non_exhaustive() + } +} + +impl<Guard> fmt::Display for PoisonError<Guard> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + "poisoned lock: another task failed inside".fmt(f) + } +} + +impl<Guard> Error for PoisonError<Guard> {} + +impl<'flag, 'key, G, Key> fmt::Debug for TryLockPoisonableError<'flag, 'key, G, Key> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Self::Poisoned(..) => "Poisoned(..)".fmt(f), + Self::WouldBlock(_) => "WouldBlock".fmt(f), + } + } +} + +impl<'flag, 'key, G, Key> fmt::Display for TryLockPoisonableError<'flag, 'key, G, Key> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Self::Poisoned(..) => "poisoned lock: another task failed inside", + Self::WouldBlock(_) => "try_lock failed because the operation would block", + } + .fmt(f) + } +} + +impl<'flag, 'key, G, Key> Error for TryLockPoisonableError<'flag, 'key, G, Key> {} + +impl<'flag, 'key, G, Key> From<PoisonError<PoisonGuard<'flag, 'key, G, Key>>> + for TryLockPoisonableError<'flag, 'key, G, Key> +{ + fn from(value: PoisonError<PoisonGuard<'flag, 'key, G, Key>>) -> Self { + Self::Poisoned(value) + } +} |
