fix usage of newly stablized inner_deref/as_deref

This commit is contained in:
Manuel Woelker 2020-06-10 13:09:18 +02:00
parent 6d6e5407a3
commit 406b325c54
4 changed files with 8 additions and 7 deletions

View File

@ -83,8 +83,9 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
.config .config
.get("output.html.input-404") .get("output.html.input-404")
.map(toml::Value::as_str) .map(toml::Value::as_str)
.flatten(); .flatten()
let file_404 = get_404_output_file(input_404); .map(ToString::to_string);
let file_404 = get_404_output_file(&input_404);
// A channel used to broadcast to any websockets to reload when a file changes. // A channel used to broadcast to any websockets to reload when a file changes.
let (tx, _rx) = tokio::sync::broadcast::channel::<Message>(100); let (tx, _rx) = tokio::sync::broadcast::channel::<Message>(100);

View File

@ -1023,7 +1023,7 @@ mod tests {
let html_config = got.html_config().unwrap(); let html_config = got.html_config().unwrap();
assert_eq!(html_config.input_404, None); assert_eq!(html_config.input_404, None);
assert_eq!( assert_eq!(
&get_404_output_file(html_config.input_404.as_deref()), &get_404_output_file(&html_config.input_404),
"404.html" "404.html"
); );
} }
@ -1040,7 +1040,7 @@ mod tests {
let html_config = got.html_config().unwrap(); let html_config = got.html_config().unwrap();
assert_eq!(html_config.input_404, Some("missing.md".to_string())); assert_eq!(html_config.input_404, Some("missing.md".to_string()));
assert_eq!( assert_eq!(
&get_404_output_file(html_config.input_404.as_deref()), &get_404_output_file(&html_config.input_404),
"missing.html" "missing.html"
); );
} }

View File

@ -152,7 +152,7 @@ impl HtmlHandlebars {
let rendered = handlebars.render("index", &data_404)?; let rendered = handlebars.render("index", &data_404)?;
let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition); let rendered = self.post_process(rendered, &html_config.playpen, ctx.config.rust.edition);
let output_file = get_404_output_file(html_config.input_404.as_deref()); let output_file = get_404_output_file(&html_config.input_404);
utils::fs::write_file(&destination, output_file, rendered.as_bytes())?; utils::fs::write_file(&destination, output_file, rendered.as_bytes())?;
debug!("Creating 404.html ✓"); debug!("Creating 404.html ✓");
Ok(()) Ok(())

View File

@ -177,8 +177,8 @@ pub fn copy_files_except_ext(
Ok(()) Ok(())
} }
pub fn get_404_output_file(input_404: Option<&str>) -> String { pub fn get_404_output_file(input_404: &Option<String>) -> String {
input_404.unwrap_or("404.md").replace(".md", ".html") input_404.as_ref().unwrap_or(&"404.md".to_string()).replace(".md", ".html")
} }
#[cfg(test)] #[cfg(test)]