Simplified the RenderError class.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user