Skip to content

Commit cfa83ca

Browse files
committed
chore: Fix clippy lints
1 parent 15bb2a4 commit cfa83ca

File tree

2 files changed

+24
-22
lines changed
  • crates
    • k8s-version/src
    • stackable-versioned-macros/src/codegen/container/struct

2 files changed

+24
-22
lines changed

crates/k8s-version/src/group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl FromStr for Group {
5353

5454
impl fmt::Display for Group {
5555
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
56-
f.write_str(&*self)
56+
f.write_str(self)
5757
}
5858
}
5959

crates/stackable-versioned-macros/src/codegen/container/struct/k8s.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, ops::Not as _};
1+
use std::{borrow::Cow, cmp::Ordering, ops::Not as _};
22

33
use darling::util::IdentString;
44
use indoc::formatdoc;
@@ -580,7 +580,7 @@ struct TracingTokens {
580580
try_convert_instrumentation: Option<TokenStream>,
581581
}
582582

583-
fn conversion_path<'a, T>(elements: &'a [T]) -> Vec<(&'a T, Cow<'a, [T]>)>
583+
fn conversion_path<T>(elements: &[T]) -> Vec<(&T, Cow<'_, [T]>)>
584584
where
585585
T: Clone + Ord,
586586
{
@@ -611,26 +611,28 @@ where
611611
elements.iter().position(|v| v == start),
612612
elements.iter().position(|v| v == end),
613613
) {
614-
let path = if start_index < end_index {
615-
// If the start index is smaller than the end index (upgrade), we can return
616-
// a slice pointing directly into the original slice. That's why Cow::Borrowed
617-
// can be used here.
618-
Cow::Borrowed(&elements[start_index + 1..=end_index])
619-
} else if start_index > end_index {
620-
// If the start index is bigger than the end index (downgrade), we need to reverse
621-
// the elements. With a slice, this is only possible to do in place, which is not
622-
// what we want in this case. Instead, the data is reversed and cloned and collected
623-
// into a Vec and Cow::Owned is used.
624-
let path = elements[end_index..start_index]
625-
.iter()
626-
.rev()
627-
.cloned()
628-
.collect();
629-
Cow::Owned(path)
630-
} else {
631-
unreachable!(
614+
let path = match start_index.cmp(&end_index) {
615+
Ordering::Less => {
616+
// If the start index is smaller than the end index (upgrade), we can return
617+
// a slice pointing directly into the original slice. That's why Cow::Borrowed
618+
// can be used here.
619+
Cow::Borrowed(&elements[start_index + 1..=end_index])
620+
}
621+
Ordering::Greater => {
622+
// If the start index is bigger than the end index (downgrade), we need to reverse
623+
// the elements. With a slice, this is only possible to do in place, which is not
624+
// what we want in this case. Instead, the data is reversed and cloned and collected
625+
// into a Vec and Cow::Owned is used.
626+
let path = elements[end_index..start_index]
627+
.iter()
628+
.rev()
629+
.cloned()
630+
.collect();
631+
Cow::Owned(path)
632+
}
633+
Ordering::Equal => unreachable!(
632634
"start and end index cannot be the same due to selecting permutations"
633-
);
635+
),
634636
};
635637

636638
chain.push((start, path));

0 commit comments

Comments
 (0)