1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::fmt;
use std::fmt::Display;
use std::error::Error;
#[allow(unused_imports)]
use crate::Semaphore;
#[derive(Debug, Eq, Ord, PartialOrd, PartialEq, Clone, Copy, Hash, Default)]
pub struct PoisonError;
impl Error for PoisonError {}
impl Display for PoisonError {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> fmt::Result {
Display::fmt("the semaphore has been poisoned", f)
}
}
#[derive(Debug, Eq, Ord, PartialOrd, PartialEq, Clone, Copy, Hash)]
pub enum TryAcquireError {
WouldBlock,
Poisoned,
}
impl Error for TryAcquireError {}
impl Display for TryAcquireError {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TryAcquireError::WouldBlock => Display::fmt("the call to acquire would have blocked", f),
TryAcquireError::Poisoned => Display::fmt(&PoisonError, f),
}
}
}
impl From<PoisonError> for TryAcquireError {
fn from(_: PoisonError) -> Self {
TryAcquireError::Poisoned
}
}