aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar René Kijewski <kijewski@library.vetmed.fu-berlin.de>2021-06-30 15:24:38 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-07-01 10:24:32 +0200
commit5afabbc7e3ae7146d14c95735850edfd7f705421 (patch)
treebc7c9dfc5036135e80614a3597a70bb44619c05f /askama_shared/src/generator.rs
parentc3e8b2cc724abc063f731ba5a222324b95b72042 (diff)
downloadaskama-5afabbc7e3ae7146d14c95735850edfd7f705421.tar.gz
askama-5afabbc7e3ae7146d14c95735850edfd7f705421.tar.bz2
askama-5afabbc7e3ae7146d14c95735850edfd7f705421.zip
Use "if let Some(_)" instead of match
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r--askama_shared/src/generator.rs39
1 files changed, 18 insertions, 21 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index ddcc1d8..24a4a71 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -484,29 +484,26 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
}
let mut arm_size = 0;
- match *cond {
- Some(ref expr) => {
- if i == 0 {
- buf.write("if ");
- } else {
- buf.dedent()?;
- buf.write("} else if ");
- }
- // The following syntax `*(&(...) as &bool)` is used to
- // trigger Rust's automatic dereferencing, to coerce
- // e.g. `&&&&&bool` to `bool`. First `&(...) as &bool`
- // coerces e.g. `&&&bool` to `&bool`. Then `*(&bool)`
- // finally dereferences it to `bool`.
- buf.write("*(&(");
- let expr_code = self.visit_expr_root(expr)?;
- buf.write(&expr_code);
- buf.write(") as &bool)");
- }
- None => {
+ if let Some(expr) = cond {
+ if i == 0 {
+ buf.write("if ");
+ } else {
buf.dedent()?;
- buf.write("} else");
- has_else = true;
+ buf.write("} else if ");
}
+ // The following syntax `*(&(...) as &bool)` is used to
+ // trigger Rust's automatic dereferencing, to coerce
+ // e.g. `&&&&&bool` to `bool`. First `&(...) as &bool`
+ // coerces e.g. `&&&bool` to `&bool`. Then `*(&bool)`
+ // finally dereferences it to `bool`.
+ buf.write("*(&(");
+ let expr_code = self.visit_expr_root(expr)?;
+ buf.write(&expr_code);
+ buf.write(") as &bool)");
+ } else {
+ buf.dedent()?;
+ buf.write("} else");
+ has_else = true;
}
buf.writeln(" {")?;