diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-06-28 13:54:13 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-06-28 15:39:19 +0200 |
commit | f408600cc34434ccf399e431a7a6d2c2041f2a90 (patch) | |
tree | 58af3191e3ff743f2711b9addbb0f5d92612269d /askama_derive/src | |
parent | f146ac920e5080e68efb9c9b443926b7677ccc7c (diff) | |
download | askama-f408600cc34434ccf399e431a7a6d2c2041f2a90.tar.gz askama-f408600cc34434ccf399e431a7a6d2c2041f2a90.tar.bz2 askama-f408600cc34434ccf399e431a7a6d2c2041f2a90.zip |
Inline child() method to avoid borrowing all fields
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/generator.rs | 50 |
1 files changed, 23 insertions, 27 deletions
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<String, CompileError> { 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) } |