restrict clippy::string_slice

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk committed 2024-07-08 22:02:10 +00:00
1 parent 51df946911
commit 59d86d3641
5 files changed
+7 -2

No files matched your search

+3 -2
View File
@@ -9,12 +9,13 @@ pub const EMPTY: &str = "";
/// common_prefix(&input) == "con";
/// ```
#[must_use]
#[allow(clippy::string_slice)]
pub fn common_prefix<'a>(choice: &'a [&str]) -> &'a str {
choice.first().map_or(EMPTY, move |best| {
choice.iter().skip(1).fold(*best, |best, choice| {
&best[0..choice
.chars()
.zip(best.chars())
.char_indices()
.zip(best.char_indices())
.take_while(|&(a, b)| a == b)
.count()]
})