From 88d3b59c71df79ba4423693020964412c2ba65be Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 2 Jul 2018 19:14:06 -0700 Subject: [PATCH] Use 'or_else' to tidy up 'Template::show()'. --- contrib/lib/src/templates/mod.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs index a497b32c..f0fe1dfa 100644 --- a/contrib/lib/src/templates/mod.rs +++ b/contrib/lib/src/templates/mod.rs @@ -287,15 +287,13 @@ impl Template { pub fn show(rocket: &Rocket, name: S, context: C) -> Option where S: Into>, C: Serialize { - let ctxt = match rocket.state::() { - Some(ctxt) => ctxt, - None => { - warn!("Uninitialized template context: missing fairing."); - info!("To use templates, you must attach `Template::fairing()`."); - info!("See the `Template` documentation for more information."); - return None; - } - }; + let ctxt = rocket.state::().or_else(|| { + warn!("Uninitialized template context: missing fairing."); + info!("To use templates, you must attach `Template::fairing()`."); + info!("See the `Template` documentation for more information."); + None + })?; + Template::render(name, context).finalize(&ctxt).ok().map(|v| v.0) }