use Fail;
use std::error::Error;
use std::fmt::{self, Debug, Display};
use std::sync::Mutex;
pub struct SyncFailure<T> {
inner: Mutex<T>,
}
impl<E: Error + Send + 'static> SyncFailure<E> {
pub fn new(err: E) -> Self {
SyncFailure {
inner: Mutex::new(err),
}
}
}
impl<T> Display for SyncFailure<T>
where
T: Display,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.inner.lock().unwrap().fmt(f)
}
}
impl<T> Debug for SyncFailure<T>
where
T: Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
(*self.inner.lock().unwrap()).fmt(f)
}
}
impl<E: Error + Send + 'static> Fail for SyncFailure<E> {}