use std::{error::Error as StdError, fmt};
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum CoreError
{
Msg(String),
PanicCapture(String),
PanicCaptureFailure,
}
impl CoreError
{
pub fn msg<T: AsRef<str>>(msg: T) -> CoreError
{
CoreError::Msg(msg.as_ref().to_owned())
}
pub fn panic_capture<T: AsRef<str>>(msg: T) -> CoreError
{
CoreError::PanicCapture(msg.as_ref().to_owned())
}
}
impl StdError for CoreError {}
impl fmt::Display for CoreError
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{
match *self {
CoreError::Msg(ref msg) => write!(f, "{}", msg),
CoreError::PanicCapture(ref msg) => write!(f, "{}", msg),
CoreError::PanicCaptureFailure => write!(f, "an error occured during a panic capture"),
}
}
}
#[cfg(test)]
mod tests
{
use crate::errors::*;
#[test]
fn test_errors()
{
assert_eq!(CoreError::msg("foo").to_string(), "foo");
assert_eq!(CoreError::Msg("foo".to_string()).to_string(), "foo");
assert_eq!(CoreError::PanicCapture("foo".to_string()).to_string(), "foo");
assert_eq!(CoreError::PanicCaptureFailure.to_string(), "an error occured during a panic capture");
}
}