From 6fd19bfe1e123692f0909c323e7a042b81a8389d Mon Sep 17 00:00:00 2001 From: Dylan Bowker Date: Thu, 28 Mar 2024 21:24:48 -0600 Subject: [PATCH] Applied `clippy` suggestions --- src/simple/builder.rs | 2 +- .../context_damerau_levenshtein.rs | 2 +- .../autocomplete/context_jaro_winkler.rs | 2 +- .../autocomplete/context_levenshtein.rs | 2 +- .../strsim/autocomplete/global_levenshtein.rs | 2 +- .../internal/strsim/autocomplete/mod.rs | 20 +++++++++---------- src/simple/internal/strsim/keyword/mod.rs | 10 +++++----- .../internal/strsim/strsim_autocomplete.rs | 11 +++++----- .../strsim/strsim_context_autocomplete.rs | 1 + .../strsim/strsim_global_autocomplete.rs | 1 + .../internal/strsim/strsim_global_keyword.rs | 1 + src/simple/internal/strsim/strsim_keyword.rs | 13 ++++++------ src/simple/search/live.rs | 4 ++-- 13 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/simple/builder.rs b/src/simple/builder.rs index 6421f42..d18f193 100644 --- a/src/simple/builder.rs +++ b/src/simple/builder.rs @@ -133,7 +133,7 @@ impl SearchIndexBuilder { /// /// [`StrsimMetric`]: enum.StrsimMetric.html #[cfg(feature = "strsim")] - pub const fn strsim_metric(mut self, strsim_metric: Option) -> Self { + #[must_use] pub const fn strsim_metric(mut self, strsim_metric: Option) -> Self { self.strsim_metric = strsim_metric; self } // fn diff --git a/src/simple/internal/strsim/autocomplete/context_damerau_levenshtein.rs b/src/simple/internal/strsim/autocomplete/context_damerau_levenshtein.rs index 8d72722..cad746c 100644 --- a/src/simple/internal/strsim/autocomplete/context_damerau_levenshtein.rs +++ b/src/simple/internal/strsim/autocomplete/context_damerau_levenshtein.rs @@ -70,7 +70,7 @@ impl SearchIndex { // Insert the score into the top scores (if it's normal and high // enough): if score.is_normal() && score >= self.fuzzy_minimum_score { - top_scores.insert(index_keyword, index_keys, score) + top_scores.insert(index_keyword, index_keys, score); } // if }); // for_each diff --git a/src/simple/internal/strsim/autocomplete/context_jaro_winkler.rs b/src/simple/internal/strsim/autocomplete/context_jaro_winkler.rs index 681ff37..ce936fa 100644 --- a/src/simple/internal/strsim/autocomplete/context_jaro_winkler.rs +++ b/src/simple/internal/strsim/autocomplete/context_jaro_winkler.rs @@ -70,7 +70,7 @@ impl SearchIndex { // Insert the score into the top scores (if it's normal and high // enough): if score.is_normal() && score >= self.fuzzy_minimum_score { - top_scores.insert(index_keyword, index_keys, score) + top_scores.insert(index_keyword, index_keys, score); } // if }); // for_each diff --git a/src/simple/internal/strsim/autocomplete/context_levenshtein.rs b/src/simple/internal/strsim/autocomplete/context_levenshtein.rs index c77a12a..a4e73b5 100644 --- a/src/simple/internal/strsim/autocomplete/context_levenshtein.rs +++ b/src/simple/internal/strsim/autocomplete/context_levenshtein.rs @@ -70,7 +70,7 @@ impl SearchIndex { // Insert the score into the top scores (if it's normal and high // enough): if score.is_normal() && score >= self.fuzzy_minimum_score { - top_scores.insert(index_keyword, index_keys, score) + top_scores.insert(index_keyword, index_keys, score); } // if }); // for_each diff --git a/src/simple/internal/strsim/autocomplete/global_levenshtein.rs b/src/simple/internal/strsim/autocomplete/global_levenshtein.rs index 139cb6e..e8463ed 100644 --- a/src/simple/internal/strsim/autocomplete/global_levenshtein.rs +++ b/src/simple/internal/strsim/autocomplete/global_levenshtein.rs @@ -54,7 +54,7 @@ impl SearchIndex { // Insert the score into the top scores (if it's normal and high // enough): if score.is_normal() && score >= self.fuzzy_minimum_score { - top_scores.insert(index_keyword, index_keys, score) + top_scores.insert(index_keyword, index_keys, score); } // if }); // for_each diff --git a/src/simple/internal/strsim/autocomplete/mod.rs b/src/simple/internal/strsim/autocomplete/mod.rs index d9b9724..1d98b6b 100644 --- a/src/simple/internal/strsim/autocomplete/mod.rs +++ b/src/simple/internal/strsim/autocomplete/mod.rs @@ -1,12 +1,12 @@ //! Fuzzy matching for autocompletion. -pub(crate) mod context_damerau_levenshtein; -pub(crate) mod context_jaro; -pub(crate) mod context_jaro_winkler; -pub(crate) mod context_levenshtein; -pub(crate) mod context_sorensen_dice; -pub(crate) mod global_damerau_levenshtein; -pub(crate) mod global_jaro; -pub(crate) mod global_jaro_winkler; -pub(crate) mod global_levenshtein; -pub(crate) mod global_sorensen_dice; +pub mod context_damerau_levenshtein; +pub mod context_jaro; +pub mod context_jaro_winkler; +pub mod context_levenshtein; +pub mod context_sorensen_dice; +pub mod global_damerau_levenshtein; +pub mod global_jaro; +pub mod global_jaro_winkler; +pub mod global_levenshtein; +pub mod global_sorensen_dice; diff --git a/src/simple/internal/strsim/keyword/mod.rs b/src/simple/internal/strsim/keyword/mod.rs index 3313a33..2113196 100644 --- a/src/simple/internal/strsim/keyword/mod.rs +++ b/src/simple/internal/strsim/keyword/mod.rs @@ -1,7 +1,7 @@ //! Fuzzy matching for keyword substitution. -pub(crate) mod global_damerau_levenshtein; -pub(crate) mod global_jaro; -pub(crate) mod global_jaro_winkler; -pub(crate) mod global_levenshtein; -pub(crate) mod global_sorensen_dice; +pub mod global_damerau_levenshtein; +pub mod global_jaro; +pub mod global_jaro_winkler; +pub mod global_levenshtein; +pub mod global_sorensen_dice; diff --git a/src/simple/internal/strsim/strsim_autocomplete.rs b/src/simple/internal/strsim/strsim_autocomplete.rs index 03d6090..5fac57c 100644 --- a/src/simple/internal/strsim/strsim_autocomplete.rs +++ b/src/simple/internal/strsim/strsim_autocomplete.rs @@ -87,13 +87,14 @@ impl SearchIndex { /// ); /// ``` - pub fn strsim_autocomplete(&self, keyword: &str) -> Vec<&str> { + #[must_use] pub fn strsim_autocomplete(&self, keyword: &str) -> Vec<&str> { // If case sensitivity set, leave case intact. Otherwise, normalize // keyword to lower case: - let keyword = match self.case_sensitive { - true => keyword.to_string(), - false => keyword.to_lowercase(), - }; // match + let keyword = if self.case_sensitive { + keyword.to_string() + } else { + keyword.to_lowercase() + }; // Call global autocompletion provider: self.strsim_global_autocomplete(&keyword) diff --git a/src/simple/internal/strsim/strsim_context_autocomplete.rs b/src/simple/internal/strsim/strsim_context_autocomplete.rs index 64a9337..f99d90a 100644 --- a/src/simple/internal/strsim/strsim_context_autocomplete.rs +++ b/src/simple/internal/strsim/strsim_context_autocomplete.rs @@ -63,6 +63,7 @@ impl SearchIndex { // Attempt to find the top matches for the user's (partial) keyword // using the selected string similarity metric defined in the // `SearchIndex`: + #[allow(clippy::option_if_let_else)] // This lint makes things less readable 👎 if let Some(strsim_metric) = &self.strsim_metric { match strsim_metric { StrsimMetric::DamerauLevenshtein => self diff --git a/src/simple/internal/strsim/strsim_global_autocomplete.rs b/src/simple/internal/strsim/strsim_global_autocomplete.rs index 565455d..329ea1e 100644 --- a/src/simple/internal/strsim/strsim_global_autocomplete.rs +++ b/src/simple/internal/strsim/strsim_global_autocomplete.rs @@ -62,6 +62,7 @@ impl SearchIndex { // Attempt to find the top matches for the user's (partial) keyword // using the selected string similarity metric defined in the // `SearchIndex`: + #[allow(clippy::option_if_let_else)] // I don't like this lint if let Some(strsim_metric) = &self.strsim_metric { match strsim_metric { StrsimMetric::DamerauLevenshtein => self diff --git a/src/simple/internal/strsim/strsim_global_keyword.rs b/src/simple/internal/strsim/strsim_global_keyword.rs index 92bd9fd..a3012fc 100644 --- a/src/simple/internal/strsim/strsim_global_keyword.rs +++ b/src/simple/internal/strsim/strsim_global_keyword.rs @@ -57,6 +57,7 @@ impl SearchIndex { // Attempt to find the closest match for the user's keyword using the // selected string similarity metric defined in the `SearchIndex`: + #[allow(clippy::option_if_let_else)] // I hate this lint if let Some(strsim_metric) = &self.strsim_metric { match strsim_metric { StrsimMetric::DamerauLevenshtein => { diff --git a/src/simple/internal/strsim/strsim_keyword.rs b/src/simple/internal/strsim/strsim_keyword.rs index d498c9f..1a3262e 100644 --- a/src/simple/internal/strsim/strsim_keyword.rs +++ b/src/simple/internal/strsim/strsim_keyword.rs @@ -82,16 +82,17 @@ impl SearchIndex { /// ); /// ``` - pub fn strsim_keyword(&self, keyword: &str) -> Option<&str> { + #[must_use] pub fn strsim_keyword(&self, keyword: &str) -> Option<&str> { // If case sensitivity set, leave case intact. Otherwise, normalize // keyword to lower case: - let keyword = match self.case_sensitive { - true => keyword.to_string(), - false => keyword.to_lowercase(), - }; // match + let keyword = if self.case_sensitive { + keyword.to_string() + } else { + keyword.to_lowercase() + }; // if // Call global keyword subtitution provider: self.strsim_global_keyword(&keyword) - .map(|kstring| kstring.as_str()) + .map(kstring::KStringBase::as_str) } // fn } // impl diff --git a/src/simple/search/live.rs b/src/simple/search/live.rs index 8c925af..e661542 100644 --- a/src/simple/search/live.rs +++ b/src/simple/search/live.rs @@ -182,7 +182,7 @@ impl SearchIndex { .take(*maximum_search_results) // Collect all keyword autocompletions into a // `BTreeSet`: - .collect() + .collect(); } // if // Return search results to caller: @@ -296,7 +296,7 @@ impl SearchIndex { .take(*maximum_search_results) // Collect all keyword autocompletions into a // `BTreeSet`: - .collect() + .collect(); } // if // Return search results to caller: