rust-web / twig

Twig templating engine for Rust; work in progress.
http://rust-web.github.io/twig
Other
8 stars 1 forks source link

refactor error handling #14

Closed colin-kiegel closed 8 years ago

colin-kiegel commented 8 years ago

New suggestion for #1

/// Generic error with backtrace.
///
/// Wrapper around some error type `T` implementing `std::error::Error`.
/// * Adds support for a backtrace.
/// * Automatically derefs to the inner error.
pub struct Traced<T>
    where T: Error
{
    error: T,
    trace: Trace,
}

/// Trace wraps `Vec<Location>`  with specialized `Display` and `Debug` impls.
///
/// For everything else it just derefs to `Vec<Location>`.
pub struct Trace(Vec<Location>);
colin-kiegel commented 8 years ago

PS:

pub trait ErrorExt: Error {
    /// Returns generic twig error for this error code.
    /// You must provide the location, where the error occured.
    fn at(self, location: Location) -> Traced<Self>
        where Self: Sized
    {
        Traced::new(self, location)
    }
}

impl<T> ErrorExt for T where T: Error {}
Nercury commented 8 years ago

OK, let's try this.