diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-10 07:38:00 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-10 09:51:48 +0200 |
commit | cece25b0be1f09f6ab9d53d099bb244858928f57 (patch) | |
tree | 85425e3f6251eebcd6fdd5b3327119926cd9f4d2 /askama_derive | |
parent | 1e0ee705a8e295ebddd31a472990133d34ad3465 (diff) | |
download | askama-cece25b0be1f09f6ab9d53d099bb244858928f57.tar.gz askama-cece25b0be1f09f6ab9d53d099bb244858928f57.tar.bz2 askama-cece25b0be1f09f6ab9d53d099bb244858928f57.zip |
Implement Display for all Templates
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/generator.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b412c9d..713d9b6 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -47,6 +47,7 @@ pub fn generate(ast: &syn::DeriveInput, path: &str, mut nodes: Vec<Node>) -> Str } else { gen.impl_template(ast, &content); } + gen.impl_display(ast); gen.result() } @@ -490,6 +491,15 @@ impl<'a> Generator<'a> { self.writeln("}"); } + // 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) -> Result<(), ::std::fmt::Error> {"); + self.writeln("self.render_into(f)"); + self.writeln("}"); + self.writeln("}"); + } + // Implement `Deref<Parent>` for an inheriting context struct. fn deref_to_parent(&mut self, ast: &syn::DeriveInput, parent_type: &syn::Ty) { self.write_header(ast, "::std::ops::Deref"); |