From 7c7042d1dd1765a8850387e52716f2015c99686f Mon Sep 17 00:00:00 2001 From: Nick Groenen Date: Fri, 12 Feb 2021 13:27:04 +0100 Subject: [PATCH] Apply clippy suggestions following rust 1.50.0 --- src/lib.rs | 29 ++++++++++++++--------------- src/main.rs | 14 +++++++------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6475bad..da15012 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,7 +133,7 @@ impl Context { /// Create a new `Context` fn new(file: PathBuf) -> Context { Context { - file_tree: vec![file.clone()], + file_tree: vec![file], frontmatter_strategy: FrontmatterStrategy::Auto, } } @@ -205,17 +205,16 @@ impl<'a> ObsidianNoteReference<'a> { impl<'a> fmt::Display for ObsidianNoteReference<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let label = self - .label - .map(|v| v.to_string()) - .unwrap_or_else(|| match (self.file, self.section) { - (Some(file), Some(section)) => format!("{} > {}", file, section), - (Some(file), None) => file.to_string(), - (None, Some(section)) => section.to_string(), + let label = + self.label + .map(|v| v.to_string()) + .unwrap_or_else(|| match (self.file, self.section) { + (Some(file), Some(section)) => format!("{} > {}", file, section), + (Some(file), None) => file.to_string(), + (None, Some(section)) => section.to_string(), - _ => panic!("Reference exists without file or section!"), - }) - .to_string(); + _ => panic!("Reference exists without file or section!"), + }); write!(f, "{}", label) } } @@ -346,10 +345,10 @@ impl<'a> Exporter<'a> { let write_frontmatter = match frontmatter_strategy { FrontmatterStrategy::Always => true, FrontmatterStrategy::Never => false, - FrontmatterStrategy::Auto => frontmatter != "", + FrontmatterStrategy::Auto => !frontmatter.is_empty(), }; if write_frontmatter { - if frontmatter != "" && !frontmatter.ends_with('\n') { + if !frontmatter.is_empty() && !frontmatter.ends_with('\n') { frontmatter.push('\n'); } outfile @@ -456,7 +455,7 @@ impl<'a> Exporter<'a> { // - If the file being embedded is a note, it's content is included at the point of embed. // - If the file is an image, an image tag is generated. // - For other types of file, a regular link is created instead. - fn embed_file<'b>(&self, link_text: &'a str, context: &'a Context) -> Result> { + fn embed_file(&self, link_text: &'a str, context: &'a Context) -> Result> { let note_ref = ObsidianNoteReference::from_str(link_text); let path = match note_ref.file { @@ -579,7 +578,7 @@ impl<'a> Exporter<'a> { let link_tag = pulldown_cmark::Tag::Link( pulldown_cmark::LinkType::Inline, - CowStr::from(link.to_string()), + CowStr::from(link), CowStr::from(""), ); diff --git a/src/main.rs b/src/main.rs index 8a1464f..0d2be39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,15 +49,17 @@ fn frontmatter_strategy_from_str(input: &str) -> Result { } } -fn main() -> Result<()> { +fn main() { let args = Opts::parse_args_default_or_exit(); let source = args.source.unwrap(); let destination = args.destination.unwrap(); - let mut walk_options = WalkOptions::default(); - walk_options.ignore_filename = &args.ignore_file; - walk_options.ignore_hidden = !args.hidden; - walk_options.honor_gitignore = !args.no_git; + let walk_options = WalkOptions { + ignore_filename: &args.ignore_file, + ignore_hidden: !args.hidden, + honor_gitignore: !args.no_git, + ..Default::default() + }; let mut exporter = Exporter::new(source, destination); exporter.frontmatter_strategy(args.frontmatter_strategy); @@ -93,6 +95,4 @@ fn main() -> Result<()> { }; std::process::exit(1); }; - - Ok(()) }