1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::fmt::{Debug, Display, Formatter};
use std::sync::PoisonError;

/// There is only one error type in this library - it's PoisonError from std::sync.
#[derive(Debug)]
pub enum Error {
    LockError(String),
}

impl<T> From<PoisonError<T>> for Error {
    fn from(err: PoisonError<T>) -> Self {
        Self::LockError(err.to_string())
    }
}

impl Display for Error {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::LockError(err) => write!(f, "Lock error: {}", err),
        }
    }
}

impl std::error::Error for Error {}