From d82a8fdf39783e3bfae6b2ea9eb08f011ba195b7 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 26 Dec 2016 16:39:30 +0100 Subject: Support templating for every type implementing Display --- askama_codegen/src/generator.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'askama_codegen') diff --git a/askama_codegen/src/generator.rs b/askama_codegen/src/generator.rs index c815676..34c9757 100644 --- a/askama_codegen/src/generator.rs +++ b/askama_codegen/src/generator.rs @@ -57,9 +57,10 @@ impl Generator { } fn visit_expr(&mut self, s: &[u8]) { - self.write("buf.push_str("); - self.write(&format!("&self.{}", str::from_utf8(s).unwrap())); - self.writeln(");"); + let var_name = str::from_utf8(s).unwrap(); + let code = format!("std::fmt::Write::write_fmt(\ + &mut buf, format_args!(\"{{}}\", self.{})).unwrap();", var_name); + self.writeln(&code); } fn handle(&mut self, tokens: &Vec) { -- cgit