From 5afabbc7e3ae7146d14c95735850edfd7f705421 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Wed, 30 Jun 2021 15:24:38 +0200 Subject: Use "if let Some(_)" instead of match --- askama_shared/src/generator.rs | 39 ++++++++++++++++++--------------------- 1 file 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(" {")?; -- cgit