mirror of https://github.com/rwf2/Rocket.git
Use 'or_else' to tidy up 'Template::show()'.
This commit is contained in:
parent
ce8817dd3c
commit
88d3b59c71
|
@ -287,15 +287,13 @@ impl Template {
|
|||
pub fn show<S, C>(rocket: &Rocket, name: S, context: C) -> Option<String>
|
||||
where S: Into<Cow<'static, str>>, C: Serialize
|
||||
{
|
||||
let ctxt = match rocket.state::<Context>() {
|
||||
Some(ctxt) => ctxt,
|
||||
None => {
|
||||
let ctxt = rocket.state::<Context>().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.");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
None
|
||||
})?;
|
||||
|
||||
Template::render(name, context).finalize(&ctxt).ok().map(|v| v.0)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue