Merge pull request #1889 from mgeisler/simplify-and-then
Simplify the use of `Option::and_then`
This commit is contained in:
commit
c8db0c8ec6
|
@ -89,8 +89,7 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||||
let input_404 = book
|
let input_404 = book
|
||||||
.config
|
.config
|
||||||
.get("output.html.input-404")
|
.get("output.html.input-404")
|
||||||
.map(toml::Value::as_str)
|
.and_then(toml::Value::as_str)
|
||||||
.and_then(std::convert::identity) // flatten
|
|
||||||
.map(ToString::to_string);
|
.map(ToString::to_string);
|
||||||
let file_404 = get_404_output_file(&input_404);
|
let file_404 = get_404_output_file(&input_404);
|
||||||
|
|
||||||
|
|
|
@ -148,15 +148,12 @@ fn render(
|
||||||
|
|
||||||
trace!("Render template");
|
trace!("Render template");
|
||||||
|
|
||||||
_h.template()
|
let t = _h
|
||||||
.ok_or_else(|| RenderError::new("Error with the handlebars template"))
|
.template()
|
||||||
.and_then(|t| {
|
.ok_or_else(|| RenderError::new("Error with the handlebars template"))?;
|
||||||
let local_ctx = Context::wraps(&context)?;
|
let local_ctx = Context::wraps(&context)?;
|
||||||
let mut local_rc = rc.clone();
|
let mut local_rc = rc.clone();
|
||||||
t.render(r, &local_ctx, &mut local_rc, out)
|
t.render(r, &local_ctx, &mut local_rc, out)
|
||||||
})?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn previous(
|
pub fn previous(
|
||||||
|
|
|
@ -117,13 +117,11 @@ impl HelperDef for RenderToc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
let path_exists = if let Some(path) =
|
let path_exists: bool;
|
||||||
item.get("path")
|
match item.get("path") {
|
||||||
.and_then(|p| if p.is_empty() { None } else { Some(p) })
|
Some(path) if !path.is_empty() => {
|
||||||
{
|
|
||||||
out.write("<a href=\"")?;
|
out.write("<a href=\"")?;
|
||||||
|
let tmp = Path::new(path)
|
||||||
let tmp = Path::new(item.get("path").expect("Error: path should be Some(_)"))
|
|
||||||
.with_extension("html")
|
.with_extension("html")
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -141,11 +139,13 @@ impl HelperDef for RenderToc {
|
||||||
}
|
}
|
||||||
|
|
||||||
out.write(">")?;
|
out.write(">")?;
|
||||||
true
|
path_exists = true;
|
||||||
} else {
|
}
|
||||||
|
_ => {
|
||||||
out.write("<div>")?;
|
out.write("<div>")?;
|
||||||
false
|
path_exists = false;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !self.no_section_label {
|
if !self.no_section_label {
|
||||||
// Section does not necessarily exist
|
// Section does not necessarily exist
|
||||||
|
|
Loading…
Reference in New Issue