2020-04-11 18:25:48 -04:00
|
|
|
use std::error;
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
2020-05-09 14:27:42 -04:00
|
|
|
pub enum RenderError {
|
2020-04-12 18:29:40 -04:00
|
|
|
Generic(String),
|
2020-05-09 14:27:42 -04:00
|
|
|
TemplateNotFound(String),
|
2020-04-11 18:25:48 -04:00
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:00:19 -04:00
|
|
|
pub enum WalkError {
|
|
|
|
|
CantWalk,
|
2020-05-09 13:54:39 -04:00
|
|
|
}
|
|
|
|
|
|
2020-04-11 18:25:48 -04:00
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct CompileError {
|
|
|
|
|
pub message: String,
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:27:42 -04:00
|
|
|
impl fmt::Display for RenderError {
|
2020-04-11 18:25:48 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-04-12 18:29:40 -04:00
|
|
|
match self {
|
|
|
|
|
RenderError::Generic(msg) => write!(f, "{}", msg),
|
2020-05-09 14:27:42 -04:00
|
|
|
RenderError::TemplateNotFound(name) => {
|
|
|
|
|
write!(f, "No template named {} in context", name)
|
2020-05-04 23:36:13 -04:00
|
|
|
}
|
2020-04-12 18:29:40 -04:00
|
|
|
}
|
2020-04-11 18:25:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:27:42 -04:00
|
|
|
impl fmt::Debug for RenderError {
|
2020-04-11 18:25:48 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-04-12 18:29:40 -04:00
|
|
|
match self {
|
|
|
|
|
RenderError::Generic(msg) => write!(f, "{}", msg),
|
2020-05-09 14:27:42 -04:00
|
|
|
RenderError::TemplateNotFound(name) => {
|
|
|
|
|
write!(f, "No template named {} in context", name)
|
2020-05-04 23:36:13 -04:00
|
|
|
}
|
2020-04-12 18:29:40 -04:00
|
|
|
}
|
2020-04-11 18:25:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:27:42 -04:00
|
|
|
impl error::Error for RenderError {
|
2020-04-11 18:25:48 -04:00
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:10:38 -04:00
|
|
|
impl fmt::Display for WalkError {
|
2020-05-09 13:54:39 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
match self {
|
2020-05-09 14:10:38 -04:00
|
|
|
WalkError::CantWalk => write!(f, "Failed to walk"),
|
2020-05-09 13:54:39 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:10:38 -04:00
|
|
|
impl fmt::Debug for WalkError {
|
2020-05-09 13:54:39 -04:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
match self {
|
2020-05-09 14:10:38 -04:00
|
|
|
WalkError::CantWalk => write!(f, "Failed to walk"),
|
2020-05-09 13:54:39 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-09 14:10:38 -04:00
|
|
|
impl error::Error for WalkError {
|
2020-05-09 13:54:39 -04:00
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-11 18:25:48 -04:00
|
|
|
impl fmt::Display for CompileError {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-04-12 21:14:21 -04:00
|
|
|
write!(f, "Error compiling: {}", self.message)
|
2020-04-11 18:25:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl fmt::Debug for CompileError {
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-04-12 21:14:21 -04:00
|
|
|
write!(f, "Error compiling: {}", self.message)
|
2020-04-11 18:25:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl error::Error for CompileError {
|
|
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|