From f408600cc34434ccf399e431a7a6d2c2041f2a90 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 28 Jun 2023 13:54:13 +0200 Subject: Inline child() method to avoid borrowing all fields --- askama_derive/src/generator.rs | 50 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'askama_derive/src') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index cfd34c5..883b11b 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -322,17 +322,6 @@ impl<'a> Generator<'a> { } } - fn child(&mut self) -> Generator<'_> { - let locals = MapChain::with_parent(&self.locals); - Self::new( - self.input, - self.contexts, - self.heritage, - locals, - self.whitespace, - ) - } - // Takes a Context and generates the relevant implementations. fn build(mut self, ctx: &'a Context<'_>) -> Result { let mut buf = Buffer::new(0); @@ -1072,23 +1061,30 @@ impl<'a> Generator<'a> { )?; } - let size_hint = { - // Since nodes must not outlive the Generator, we instantiate - // a nested Generator here to handle the include's nodes. - let mut gen = self.child(); - let mut size_hint = gen.handle( - ctx, - match &nodes { - CowNodes::Owned(parsed) => parsed.nodes(), - CowNodes::Borrowed(nodes) => nodes, - }, - buf, - AstLevel::Nested, - )?; - size_hint += gen.write_buf_writable(buf)?; - size_hint - }; + // Since nodes must not outlive the Generator, we instantiate + // a nested Generator here to handle the include's nodes. + + let locals = MapChain::with_parent(&self.locals); + let mut child = Self::new( + self.input, + self.contexts, + self.heritage, + locals, + self.whitespace, + ); + + let mut size_hint = child.handle( + ctx, + match &nodes { + CowNodes::Owned(parsed) => parsed.nodes(), + CowNodes::Borrowed(nodes) => nodes, + }, + buf, + AstLevel::Nested, + )?; + size_hint += child.write_buf_writable(buf)?; self.prepare_ws(ws); + Ok(size_hint) } -- cgit