diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index 984dd9b..bd3e931 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -62,7 +62,7 @@ async fn get_post_directories(config: &Config) -> Result, CustomErr async fn load_blog_posts(config: &Config) -> Result, CustomError> { let root_directory = config.get_root_directory().to_owned(); - let post_directories = get_post_directories(&config).await?; + let post_directories = get_post_directories(config).await?; let load_jobs = post_directories .into_iter() .map(|path| tokio::spawn(BlogPost::load_blog_post(root_directory.clone(), path))); diff --git a/src/command/init/runner.rs b/src/command/init/runner.rs index 8f13528..38bcdf0 100644 --- a/src/command/init/runner.rs +++ b/src/command/init/runner.rs @@ -13,7 +13,7 @@ pub(crate) async fn init_natter_folder(args: InitArgs) -> Result<(), CustomError let mut existing_entries = tokio::fs::read_dir(&args.path).await?; let first_entry = existing_entries.next_entry().await?; - if let Some(_) = first_entry { + if first_entry.is_some() { return Err("The directory is not empty. Aborting.".into()); } diff --git a/src/config/full.rs b/src/config/full.rs index b102a18..3c9717f 100644 --- a/src/config/full.rs +++ b/src/config/full.rs @@ -47,8 +47,7 @@ impl Config { } pub(crate) fn get_root_directory(&self) -> &Path { - &self - .config_path + self.config_path .parent() .expect("Config file must exist inside a directory.") } @@ -86,8 +85,7 @@ impl Config { self.raw .stream .as_ref() - .map(|stream| stream.entries_per_page) - .flatten() + .and_then(|stream| stream.entries_per_page) .unwrap_or(5) } } diff --git a/src/config/raw.rs b/src/config/raw.rs index b25319d..9c5b44d 100644 --- a/src/config/raw.rs +++ b/src/config/raw.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use serde::Serialize; /// This is the struct for the natter.toml config file that ends up in each site's root directory. -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Default)] pub(crate) struct RawConfig { pub(super) site_title: Option, author: Option, @@ -12,28 +12,7 @@ pub(crate) struct RawConfig { pub(super) stream: Option, } -impl Default for RawConfig { - fn default() -> Self { - RawConfig { - site_title: None, - author: None, - email: None, - use_relative_paths: None, - web_root: None, - stream: None, - } - } -} - -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Default)] pub(crate) struct RawConfigStream { pub(super) entries_per_page: Option, } - -impl Default for RawConfigStream { - fn default() -> Self { - RawConfigStream { - entries_per_page: None, - } - } -} diff --git a/src/context/ast_node.rs b/src/context/ast_node.rs index c466297..365c12f 100644 --- a/src/context/ast_node.rs +++ b/src/context/ast_node.rs @@ -117,14 +117,14 @@ pub(crate) enum RenderAstNode { } pub(crate) trait IntoRenderAstNode { - fn into_render_ast_node( + fn as_render_ast_node( &self, render_context: RenderContext<'_>, ) -> Result; } impl IntoRenderAstNode for IAstNode { - fn into_render_ast_node( + fn as_render_ast_node( &self, render_context: RenderContext<'_>, ) -> Result { diff --git a/src/context/blog_post_page.rs b/src/context/blog_post_page.rs index ed5b8d9..794b11d 100644 --- a/src/context/blog_post_page.rs +++ b/src/context/blog_post_page.rs @@ -14,6 +14,7 @@ use super::RenderDocumentElement; #[derive(Debug)] pub(crate) struct RenderBlogPostPageInput<'a> { + #[allow(dead_code)] post: &'a BlogPost, page: &'a BlogPostPage, } diff --git a/src/context/blog_stream.rs b/src/context/blog_stream.rs index 04fac51..342fdde 100644 --- a/src/context/blog_stream.rs +++ b/src/context/blog_stream.rs @@ -85,7 +85,7 @@ render!( let children = original .original - .into_iter() + .iter() .enumerate() .map(|(i, blog_post)| { RenderBlogStreamEntry::new( diff --git a/src/context/footnote_definition.rs b/src/context/footnote_definition.rs index 58e0ab0..6d28da6 100644 --- a/src/context/footnote_definition.rs +++ b/src/context/footnote_definition.rs @@ -39,7 +39,7 @@ render!( let contents = { let mut ret = Vec::new(); for obj in original.contents.iter() { - ret.push(obj.into_render_ast_node(render_context.clone())?); + ret.push(obj.as_render_ast_node(render_context.clone())?); } ret }; diff --git a/src/intermediate/ast_node.rs b/src/intermediate/ast_node.rs index 1b3110c..785f8ab 100644 --- a/src/intermediate/ast_node.rs +++ b/src/intermediate/ast_node.rs @@ -113,14 +113,14 @@ pub(crate) enum IAstNode { } pub(crate) trait IntoIAstNode<'parse> { - fn into_ast_node<'orig>( + fn as_ast_node<'orig>( &'orig self, intermediate_context: IntermediateContext<'orig, 'parse>, ) -> BoxFuture<'orig, Result>; } impl<'parse> IntoIAstNode<'parse> for organic::types::DocumentElement<'parse> { - fn into_ast_node<'orig>( + fn as_ast_node<'orig>( &'orig self, intermediate_context: IntermediateContext<'orig, 'parse>, ) -> BoxFuture<'orig, Result> { @@ -139,7 +139,7 @@ impl<'parse> IntoIAstNode<'parse> for organic::types::DocumentElement<'parse> { } impl<'parse> IntoIAstNode<'parse> for organic::types::Element<'parse> { - fn into_ast_node<'orig>( + fn as_ast_node<'orig>( &'orig self, intermediate_context: IntermediateContext<'orig, 'parse>, ) -> BoxFuture<'orig, Result> { @@ -226,7 +226,7 @@ impl<'parse> IntoIAstNode<'parse> for organic::types::Element<'parse> { } impl<'parse> IntoIAstNode<'parse> for organic::types::Object<'parse> { - fn into_ast_node<'orig>( + fn as_ast_node<'orig>( &'orig self, intermediate_context: IntermediateContext<'orig, 'parse>, ) -> BoxFuture<'orig, Result> { diff --git a/src/intermediate/blog_post.rs b/src/intermediate/blog_post.rs index ad74e79..2d66ca9 100644 --- a/src/intermediate/blog_post.rs +++ b/src/intermediate/blog_post.rs @@ -55,11 +55,10 @@ impl BlogPost { // Assign IDs to the targets organic::types::AstNode::from(parsed_document) .iter_all_ast_nodes() - .for_each(|node| match node { - organic::types::AstNode::Target(target) => { + .for_each(|node| { + if let organic::types::AstNode::Target(target) = node { registry.get_target(target.value); } - _ => {} }); let registry = Arc::new(Mutex::new(registry)); @@ -96,15 +95,14 @@ impl BlogPost { pub(crate) fn get_date(&self) -> Option<&str> { let index_page_date = self .get_index_page() - .map(|index_page| index_page.date.as_ref().map(String::as_str)) - .flatten(); + .and_then(|index_page| index_page.date.as_deref()); if index_page_date.is_some() { return index_page_date; } self.pages .iter() - .filter_map(|page| page.date.as_ref().map(String::as_str)) + .filter_map(|page| page.date.as_deref()) .next() } diff --git a/src/intermediate/convert.rs b/src/intermediate/convert.rs index ca462ef..ebaaada 100644 --- a/src/intermediate/convert.rs +++ b/src/intermediate/convert.rs @@ -21,7 +21,7 @@ pub(crate) fn get_web_path, F: AsRef, P: AsRef>( containing_file_relative_to_output_directory .parent() .ok_or("File should exist in a folder.")?, - path_from_web_root.parent().unwrap_or(&Path::new("")), + path_from_web_root.parent().unwrap_or(Path::new("")), ) .collect::(); // Subtracting 1 from the depth to "remove" the file name. diff --git a/src/intermediate/footnote_definition.rs b/src/intermediate/footnote_definition.rs index 1d612e5..38085bf 100644 --- a/src/intermediate/footnote_definition.rs +++ b/src/intermediate/footnote_definition.rs @@ -53,7 +53,7 @@ impl IRealFootnoteDefinition { pub(crate) fn get_reference_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) - .unwrap_or(String::default()); + .unwrap_or_default(); format!("{}fnr.{}", id_addition, self.get_display_label()) } @@ -64,7 +64,7 @@ impl IRealFootnoteDefinition { pub(crate) fn get_definition_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) - .unwrap_or(String::default()); + .unwrap_or_default(); format!("{}fn.{}", id_addition, self.get_display_label()) } diff --git a/src/intermediate/footnote_reference.rs b/src/intermediate/footnote_reference.rs index 75dac0f..d47e5c0 100644 --- a/src/intermediate/footnote_reference.rs +++ b/src/intermediate/footnote_reference.rs @@ -38,7 +38,7 @@ impl IFootnoteReference { pub(crate) fn get_reference_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) - .unwrap_or(String::default()); + .unwrap_or_default(); if self.duplicate_offset == 0 { format!("{}fnr.{}", id_addition, self.get_display_label()) @@ -55,7 +55,7 @@ impl IFootnoteReference { pub(crate) fn get_definition_id(&self, id_addition: Option<&str>) -> String { let id_addition = id_addition .map(|id_addition| format!("sec{}.", id_addition)) - .unwrap_or(String::default()); + .unwrap_or_default(); format!("{}fn.{}", id_addition, self.get_display_label()) } diff --git a/src/intermediate/latex_fragment.rs b/src/intermediate/latex_fragment.rs index beab9b6..48843a8 100644 --- a/src/intermediate/latex_fragment.rs +++ b/src/intermediate/latex_fragment.rs @@ -16,7 +16,7 @@ intermediate!( { let value: String = if original.value.starts_with("$$") && original.value.ends_with("$$") { format!("\\[{}\\]", &original.value[2..(original.value.len() - 2)]) - } else if original.value.starts_with("$") && original.value.ends_with("$") { + } else if original.value.starts_with('$') && original.value.ends_with('$') { format!("\\({}\\)", &original.value[1..(original.value.len() - 1)]) } else { original.value.to_owned() diff --git a/src/intermediate/plain_list_item.rs b/src/intermediate/plain_list_item.rs index 9cec4be..efc4ba3 100644 --- a/src/intermediate/plain_list_item.rs +++ b/src/intermediate/plain_list_item.rs @@ -29,11 +29,11 @@ intermediate!( let mut ret = Vec::new(); // Special case for list items with only paragraphs and sublists as their children. In those cases, the paragraph tags are omitted. - let is_simple_list_item = original.children.iter().all(|child| match child { - organic::types::Element::Paragraph(_) | organic::types::Element::PlainList(_) => { - true - } - _ => false, + let is_simple_list_item = original.children.iter().all(|child| { + matches!( + child, + organic::types::Element::Paragraph(_) | organic::types::Element::PlainList(_) + ) }); if is_simple_list_item { for elem in original.children.iter() { diff --git a/src/intermediate/registry.rs b/src/intermediate/registry.rs index f1de21d..b5f6f7b 100644 --- a/src/intermediate/registry.rs +++ b/src/intermediate/registry.rs @@ -52,9 +52,9 @@ impl<'orig, 'parse> Registry<'orig, 'parse> { pub(crate) async fn get_footnote_reference_id<'orig, 'parse>( intermediate_context: IntermediateContext<'orig, 'parse>, label: Option<&'parse str>, - definition: &'orig Vec>, + definition: &'orig [Object<'parse>], ) -> Result<(usize, usize), CustomError> { - if let None = label { + if label.is_none() { // If it has no label then it must always get a new ID. let contents = convert_reference_contents(intermediate_context.clone(), definition).await?; let pos = { @@ -148,7 +148,7 @@ pub(crate) async fn register_footnote_definition<'orig, 'parse>( async fn convert_reference_contents<'orig, 'parse>( intermediate_context: IntermediateContext<'orig, 'parse>, - contents: &'orig Vec>, + contents: &'orig [Object<'parse>], ) -> Result, CustomError> { let children = { let mut ret = Vec::new(); @@ -159,23 +159,19 @@ async fn convert_reference_contents<'orig, 'parse>( }; let containing_paragraph = IParagraph::artificial(intermediate_context.clone(), children, 0).await?; - let contents = { - let mut ret = Vec::new(); - ret.push(IAstNode::Paragraph(containing_paragraph)); - ret - }; + let contents = vec![IAstNode::Paragraph(containing_paragraph)]; Ok(contents) } async fn convert_definition_contents<'orig, 'parse>( intermediate_context: IntermediateContext<'orig, 'parse>, - contents: &'orig Vec>, + contents: &'orig [Element<'parse>], ) -> Result, CustomError> { let contents = { let mut ret = Vec::new(); for obj in contents.iter() { - ret.push(obj.into_ast_node(intermediate_context.clone()).await?); + ret.push(obj.as_ast_node(intermediate_context.clone()).await?); } ret }; @@ -190,8 +186,7 @@ pub(crate) async fn promote_footnote_definition<'orig, 'parse>( ) -> Result<(), CustomError> { let definition = { let mut registry = intermediate_context.registry.lock().unwrap(); - let definition = registry.on_deck_footnote_ids.remove(label); - definition + registry.on_deck_footnote_ids.remove(label) }; if let Some(elements) = definition { let existing_id = { diff --git a/src/intermediate/table.rs b/src/intermediate/table.rs index 85ad76b..c6d0557 100644 --- a/src/intermediate/table.rs +++ b/src/intermediate/table.rs @@ -67,10 +67,10 @@ enum GroupIntoSectionsState<'orig, 'parse> { } fn group_into_sections<'orig, 'parse>( - rows: &'orig Vec>, + rows: &'orig [organic::types::TableRow<'parse>], ) -> Vec>> { let mut sections = Vec::new(); - let mut rows = rows.into_iter(); + let mut rows = rows.iter(); let mut state = GroupIntoSectionsState::NonSection; loop { state = match (state, rows.next()) { diff --git a/src/intermediate/target.rs b/src/intermediate/target.rs index e172164..0e2e255 100644 --- a/src/intermediate/target.rs +++ b/src/intermediate/target.rs @@ -5,6 +5,7 @@ use organic::types::StandardProperties; #[derive(Debug, Clone)] pub(crate) struct ITarget { pub(crate) id: String, + #[allow(dead_code)] value: String, pub(crate) post_blank: organic::types::PostBlank, } diff --git a/src/main.rs b/src/main.rs index e603fca..7feed97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,7 @@ mod render; fn main() -> Result { let rt = tokio::runtime::Runtime::new()?; - rt.block_on(async { - let main_body_result = main_body().await; - main_body_result - }) + rt.block_on(async { main_body().await }) } async fn main_body() -> Result { diff --git a/src/render/duster_renderer.rs b/src/render/duster_renderer.rs index 2208077..ca24479 100644 --- a/src/render/duster_renderer.rs +++ b/src/render/duster_renderer.rs @@ -19,7 +19,7 @@ impl<'a> DusterRenderer<'a> { impl<'a> RendererIntegration<'a> for DusterRenderer<'a> { fn load_template(&mut self, name: &'a str, contents: &'a str) -> Result<(), CustomError> { - let compiled_template = duster::renderer::compile_template(contents.as_ref())?; + let compiled_template = duster::renderer::compile_template(contents)?; self.templates.insert(name, compiled_template); Ok(()) }