diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2021-07-01 18:29:48 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-07-05 14:17:49 +0200 |
commit | 7e227907fe5d293b2d7620602d48ffba94e35dc5 (patch) | |
tree | 3dcbe0d932741fefb7a6ebf20748a9d0e2747f14 /askama_shared/src/generator.rs | |
parent | 3055c4b52160f729f27009eae5649e8201cbeecb (diff) | |
download | askama-7e227907fe5d293b2d7620602d48ffba94e35dc5.tar.gz askama-7e227907fe5d293b2d7620602d48ffba94e35dc5.tar.bz2 askama-7e227907fe5d293b2d7620602d48ffba94e35dc5.zip |
Implement destructoring of structs
This PR implements the destructoring of structs on the lhs of "let" and
"for" statements.
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index a7f52ca..36d1841 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -824,9 +824,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { _ => false, } } - Target::Tuple(targets) => targets + Target::Tuple(_, targets) => targets .iter() .any(|target| self.is_shadowing_variable(target)), + Target::Struct(_, named_targets) => named_targets + .iter() + .any(|(_, target)| self.is_shadowing_variable(target)), } } @@ -1521,7 +1524,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { } buf.write(name); } - Target::Tuple(targets) => { + Target::Tuple(path, targets) => { + buf.write(&path.join("::")); buf.write("("); for target in targets { self.visit_target(buf, initialized, target); @@ -1529,6 +1533,17 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { } buf.write(")"); } + Target::Struct(path, targets) => { + buf.write(&path.join("::")); + buf.write(" { "); + for (name, target) in targets { + buf.write(normalize_identifier(name)); + buf.write(": "); + self.visit_target(buf, initialized, target); + buf.write(","); + } + buf.write(" }"); + } } } |