diff options
-rw-r--r-- | askama/Cargo.toml | 1 | ||||
-rw-r--r-- | askama/src/lib.rs | 13 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/askama/Cargo.toml b/askama/Cargo.toml index c9ee4ed..57708ee 100644 --- a/askama/Cargo.toml +++ b/askama/Cargo.toml @@ -17,3 +17,4 @@ travis-ci = { repository = "djc/askama" } [dependencies] askama_derive = { path = "../askama_derive", version = "0.3.4" } +error-chain = "0.10" diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 6f50c60..9c1d648 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -213,6 +213,8 @@ #![allow(unused_imports)] #[macro_use] extern crate askama_derive; +#[macro_use] +extern crate error_chain; use std::env; use std::fmt; @@ -232,10 +234,9 @@ pub trait Template { } } -pub type Result<T> = std::result::Result<T, std::fmt::Error>; - pub mod filters; pub use askama_derive::*; +pub use errors::Result; // Duplicates askama_derive::path::template_dir() fn template_dir() -> PathBuf { @@ -273,3 +274,11 @@ pub fn rerun_if_templates_changed() { println!("cargo:rerun-if-changed={}", e.path().to_str().unwrap()); }).unwrap(); } + +mod errors { + error_chain! { + foreign_links { + Fmt(::std::fmt::Error); + } + } +} diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 24d34cf..b00094d 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -481,8 +481,8 @@ impl<'a> Generator<'a> { // Implement `Display` for the given context struct. fn impl_display(&mut self, ast: &syn::DeriveInput) { self.write_header(ast, "::std::fmt::Display"); - self.writeln("fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::askama::Result<()> {"); - self.writeln("self.render_into(f)"); + self.writeln("fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {"); + self.writeln("self.render_into(f).map_err(|_| ::std::fmt::Error {})"); self.writeln("}"); self.writeln("}"); } |