Initial move to returning results from render calls.
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
use crate::renderer::walkable::ContextElement;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RenderError {
|
||||
pub message: String,
|
||||
pub enum RenderError<'a> {
|
||||
Generic(String),
|
||||
/// For when walking is absolutely impossible
|
||||
CantWalk {
|
||||
segment: String,
|
||||
elem: &'a dyn ContextElement,
|
||||
},
|
||||
/// For when walking fails (example, a missing key on a map)
|
||||
WontWalk {
|
||||
segment: String,
|
||||
elem: &'a dyn ContextElement,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -11,19 +21,35 @@ 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 {
|
||||
write!(f, "Error rendering: {}", self.message)
|
||||
match self {
|
||||
RenderError::Generic(msg) => write!(f, "{}", msg),
|
||||
RenderError::CantWalk { segment, elem } => {
|
||||
write!(f, "Tried to walk to {} from {:?}", segment, elem)
|
||||
}
|
||||
RenderError::WontWalk { segment, elem } => {
|
||||
write!(f, "Failed to walk to {} from {:?}", segment, elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for RenderError {
|
||||
impl fmt::Debug for RenderError<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Error rendering: {}", self.message)
|
||||
match self {
|
||||
RenderError::Generic(msg) => write!(f, "{}", msg),
|
||||
RenderError::CantWalk { segment, elem } => {
|
||||
write!(f, "Tried to walk to {} from {:?}", segment, elem)
|
||||
}
|
||||
RenderError::WontWalk { segment, elem } => {
|
||||
write!(f, "Failed to walk to {} from {:?}", segment, elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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