mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Use error-chain to create a crate-specific Error type
This commit is contained in:
parent
69c447f0c7
commit
5f3e93da3f
@ -17,3 +17,4 @@ travis-ci = { repository = "djc/askama" }
|
||||
|
||||
[dependencies]
|
||||
askama_derive = { path = "../askama_derive", version = "0.3.4" }
|
||||
error-chain = "0.10"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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("}");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user