use std::error;
pub type Error = Box<dyn error::Error + Send + Sync>;
pub type Result<T> = std::result::Result<T, Error>;
pub fn new_error<E>(e: E) -> Error
where
E: error::Error + Send + Sync + 'static + Sized,
{
Box::new(e)
}
#[cfg(test)]
pub type ErrorForTesting = for_testing::Error;
#[cfg(test)]
mod for_testing {
use std::error;
use std::fmt;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Error {
text: String,
}
impl From<&'static str> for Error {
fn from(text: &'static str) -> Self {
Self::from(String::from(text))
}
}
impl From<String> for Error {
fn from(text: String) -> Self {
Error { text }
}
}
impl error::Error for Error {}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.text)
}
}
}