diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-14 12:22:48 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-14 12:22:48 +0200 |
commit | 9dcba34f0d873749631ab98a3504be8c1d364b9d (patch) | |
tree | 31c958966fd2d854c8fbb96a52c3d12ccfbc7e12 | |
parent | 0b814fd0fa22273a3e03664337d62de883cc5047 (diff) | |
download | askama-9dcba34f0d873749631ab98a3504be8c1d364b9d.tar.gz askama-9dcba34f0d873749631ab98a3504be8c1d364b9d.tar.bz2 askama-9dcba34f0d873749631ab98a3504be8c1d364b9d.zip |
Define type askama::Result to use for all rendering methods
Diffstat (limited to '')
-rw-r--r-- | askama/src/lib.rs | 6 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 54d211e..6f50c60 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -223,15 +223,17 @@ use std::path::{Path, PathBuf}; /// Main `Template` trait; implementations are generally derived pub trait Template { /// Renders the template to the given `writer` buffer - fn render_into(&self, writer: &mut std::fmt::Write) -> Result<(), fmt::Error>; + fn render_into(&self, writer: &mut std::fmt::Write) -> Result<()>; /// Helper method which allocates a new `String` and renders into it - fn render(&self) -> Result<String, fmt::Error> { + fn render(&self) -> Result<String> { let mut buf = String::new(); self.render_into(&mut buf)?; Ok(buf) } } +pub type Result<T> = std::result::Result<T, std::fmt::Error>; + pub mod filters; pub use askama_derive::*; diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 77d338d..24d34cf 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -368,7 +368,7 @@ impl<'a> Generator<'a> { self.writeln("#[allow(unused_variables)]"); self.writeln(&format!( "fn render_block_{}_into(&self, writer: &mut ::std::fmt::Write) \ - -> ::std::result::Result<(), ::std::fmt::Error> {{", + -> ::askama::Result<()> {{", name)); self.prepare_ws(ws1); self.handle(nodes); @@ -470,7 +470,7 @@ impl<'a> Generator<'a> { fn impl_template(&mut self, ast: &syn::DeriveInput, nodes: &'a [Node]) { self.write_header(ast, "::askama::Template"); self.writeln("fn render_into(&self, writer: &mut ::std::fmt::Write) -> \ - ::std::result::Result<(), ::std::fmt::Error> {"); + ::askama::Result<()> {"); self.handle(nodes); self.flush_ws(&WS(false, false)); self.writeln("Ok(())"); @@ -481,7 +481,7 @@ 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) -> ::std::result::Result<(), ::std::fmt::Error> {"); + self.writeln("fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::askama::Result<()> {"); self.writeln("self.render_into(f)"); self.writeln("}"); self.writeln("}"); @@ -508,7 +508,7 @@ impl<'a> Generator<'a> { self.writeln("#[allow(unused_variables)]"); self.writeln(&format!( "fn render_trait_into(&self, timpl: &{}, writer: &mut ::std::fmt::Write) \ - -> ::std::result::Result<(), ::std::fmt::Error> {{", + -> ::askama::Result<()> {{", trait_name)); if let Some(nodes) = nodes { @@ -528,7 +528,7 @@ impl<'a> Generator<'a> { fn impl_template_for_trait(&mut self, ast: &syn::DeriveInput, derived: bool) { self.write_header(ast, "::askama::Template"); self.writeln("fn render_into(&self, writer: &mut ::std::fmt::Write) \ - -> ::std::result::Result<(), ::std::fmt::Error> {"); + -> ::askama::Result<()> {"); if derived { self.writeln("self._parent.render_trait_into(self, writer)?;"); } else { @@ -546,12 +546,12 @@ impl<'a> Generator<'a> { for bname in block_names { self.writeln(&format!( "fn render_block_{}_into(&self, writer: &mut ::std::fmt::Write) \ - -> ::std::result::Result<(), ::std::fmt::Error>;", + -> ::askama::Result<()>;", bname)); } self.writeln(&format!( "fn render_trait_into(&self, timpl: &{}, writer: &mut ::std::fmt::Write) \ - -> ::std::result::Result<(), ::std::fmt::Error>;", + -> ::askama::Result<()>;", trait_name)); self.writeln("}"); } |