Fix clippy issues.
All checks were successful
rust-test Build rust-test has succeeded
rust-clippy Build rust-clippy has succeeded
build-natter Build build-natter has succeeded
format Build format has succeeded

This commit is contained in:
Tom Alexander
2023-12-23 06:38:23 -05:00
parent 818fca87f2
commit 397d4ea0bc
20 changed files with 42 additions and 73 deletions

View File

@@ -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<IAstNode, CustomError>>;
}
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<IAstNode, CustomError>> {
@@ -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<IAstNode, CustomError>> {
@@ -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<IAstNode, CustomError>> {

View File

@@ -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()
}

View File

@@ -21,7 +21,7 @@ pub(crate) fn get_web_path<D: AsRef<Path>, F: AsRef<Path>, P: AsRef<Path>>(
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::<PathBuf>();
// Subtracting 1 from the depth to "remove" the file name.

View File

@@ -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())
}

View File

@@ -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())
}

View File

@@ -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()

View File

@@ -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() {

View File

@@ -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<Object<'parse>>,
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<Object<'parse>>,
contents: &'orig [Object<'parse>],
) -> Result<Vec<IAstNode>, 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<Element<'parse>>,
contents: &'orig [Element<'parse>],
) -> Result<Vec<IAstNode>, 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 = {

View File

@@ -67,10 +67,10 @@ enum GroupIntoSectionsState<'orig, 'parse> {
}
fn group_into_sections<'orig, 'parse>(
rows: &'orig Vec<organic::types::TableRow<'parse>>,
rows: &'orig [organic::types::TableRow<'parse>],
) -> Vec<Vec<&'orig organic::types::TableRow<'parse>>> {
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()) {

View File

@@ -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,
}