diff options
author | Yusuke Sasaki <yusuke.sasaki.nuem@gmail.com> | 2018-11-04 18:04:28 +0900 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-11-04 22:14:11 +0100 |
commit | 82a406df795e2645c83d9ec0974f1f0421337d9b (patch) | |
tree | c42d240e54dc9fd66b6a55034fad72d3d4a91c62 | |
parent | efe621195e3e2459275e4985659c8b0158d0b880 (diff) | |
download | askama-82a406df795e2645c83d9ec0974f1f0421337d9b.tar.gz askama-82a406df795e2645c83d9ec0974f1f0421337d9b.tar.bz2 askama-82a406df795e2645c83d9ec0974f1f0421337d9b.zip |
use UFCS in derived code
-rw-r--r-- | askama_derive/src/generator.rs | 6 | ||||
-rw-r--r-- | testing/tests/simple.rs | 12 |
2 files changed, 16 insertions, 2 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 0395c11..e0c0efb 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -137,7 +137,7 @@ impl<'a> Generator<'a> { fn impl_display(&mut self, buf: &mut Buffer) { self.write_header(buf, "::std::fmt::Display", None); buf.writeln("fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {"); - buf.writeln("self.render_into(f).map_err(|_| ::std::fmt::Error {})"); + buf.writeln("::askama::Template::render_into(self, f).map_err(|_| ::std::fmt::Error {})"); buf.writeln("}"); buf.writeln("}"); } @@ -150,7 +150,9 @@ impl<'a> Generator<'a> { None, ); buf.writeln("fn modify(self, res: &mut ::askama::iron::Response) {"); - buf.writeln("res.body = Some(Box::new(self.render().unwrap().into_bytes()));"); + buf.writeln( + "res.body = Some(Box::new(::askama::Template::render(&self).unwrap().into_bytes()));", + ); let ext = self .input diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index d4d2964..2bf8e7a 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -289,3 +289,15 @@ struct Empty; fn test_empty() { assert_eq!(Empty.render().unwrap(), "foo"); } + +mod without_import_on_derive { + #[derive(askama::Template)] + #[template(source = "foo", ext = "txt")] + struct WithoutImport; + + #[test] + fn test_without_import() { + use askama::Template; + assert_eq!(WithoutImport.render().unwrap(), "foo"); + } +} |