mirror of
https://github.com/rwf2/Rocket.git
synced 2025-02-17 14:12:07 +00:00
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>
|
pub fn show<S, C>(rocket: &Rocket, name: S, context: C) -> Option<String>
|
||||||
where S: Into<Cow<'static, str>>, C: Serialize
|
where S: Into<Cow<'static, str>>, C: Serialize
|
||||||
{
|
{
|
||||||
let ctxt = match rocket.state::<Context>() {
|
let ctxt = rocket.state::<Context>().or_else(|| {
|
||||||
Some(ctxt) => ctxt,
|
warn!("Uninitialized template context: missing fairing.");
|
||||||
None => {
|
info!("To use templates, you must attach `Template::fairing()`.");
|
||||||
warn!("Uninitialized template context: missing fairing.");
|
info!("See the `Template` documentation for more information.");
|
||||||
info!("To use templates, you must attach `Template::fairing()`.");
|
None
|
||||||
info!("See the `Template` documentation for more information.");
|
})?;
|
||||||
return None;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Template::render(name, context).finalize(&ctxt).ok().map(|v| v.0)
|
Template::render(name, context).finalize(&ctxt).ok().map(|v| v.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user