Simplified the RenderError class.

This commit is contained in:
Tom Alexander
2020-05-09 14:27:42 -04:00
parent 05b56e83a9
commit 5d7c991bf0
2 changed files with 14 additions and 33 deletions

View File

@@ -1,18 +1,9 @@
use crate::renderer::context_element::ContextElement;
use std::error;
use std::fmt;
pub enum RenderError<'a> {
pub enum RenderError {
Generic(String),
/// For when walking fails (example, a missing key on a map)
CantWalk {
segment: String,
elem: &'a dyn ContextElement,
},
NotFound {
path: &'a Vec<&'a str>,
breadcrumbs: Vec<&'a dyn ContextElement>,
},
TemplateNotFound(String),
}
pub enum WalkError {
@@ -24,35 +15,29 @@ pub struct CompileError {
pub message: String,
}
impl fmt::Display for RenderError<'_> {
impl fmt::Display for RenderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RenderError::Generic(msg) => write!(f, "{}", msg),
RenderError::CantWalk { segment, elem } => {
write!(f, "Tried to walk to {} from {:?}", segment, elem)
}
RenderError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
RenderError::TemplateNotFound(name) => {
write!(f, "No template named {} in context", name)
}
}
}
}
impl fmt::Debug for RenderError<'_> {
impl fmt::Debug for RenderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
RenderError::Generic(msg) => write!(f, "{}", msg),
RenderError::CantWalk { segment, elem } => {
write!(f, "Tried to walk to {} from {:?}", segment, elem)
}
RenderError::NotFound { path, breadcrumbs } => {
write!(f, "Could not find {:?} in {:?}", path, breadcrumbs)
RenderError::TemplateNotFound(name) => {
write!(f, "No template named {} in context", name)
}
}
}
}
impl error::Error for RenderError<'_> {
impl error::Error for RenderError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
None
}