restrict clippy::string_slice
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
51df946911
commit
59d86d3641
5 changed files with 7 additions and 2 deletions
|
@ -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()]
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue