use crate::ErrorKind;
use crate::Context;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Error {
pub kind: ErrorKind,
pub context: Option<Context>,
}
impl Error {
pub fn new<T: Into<Context>>(kind: ErrorKind, context: Option<T>) -> Self {
Error {
kind,
context: context.map(|t| t.into()),
}
}
}
#[cfg(feature = "issue-names")]
impl Error {
pub fn get_name(&self) -> &str {
self.kind.get_name()
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} at {:?}", self.kind, self.context)
}
}