Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ockajak committed Jul 19, 2024
1 parent 1fcdbae commit 2761dce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/extensions/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,12 @@ impl<Item> Sequence<Item> for LinkedList<Item> {
}
fn move_at(self, source_index: usize, target_index: usize) -> Self {
if source_index == target_index {
let size = self.len();
if source_index >= size {
panic!(r#"source index (is {source_index:?}) should be < len (is {size:?})"#)
}
return self;
};
}
let mut iterator = self.into_iter();
let mut index = 0_usize;
if source_index <= target_index {
Expand Down Expand Up @@ -406,8 +410,12 @@ impl<Item> Sequence<Item> for LinkedList<Item> {

fn swap_at(self, source_index: usize, target_index: usize) -> Self {
if source_index == target_index {
let size = self.len();
if source_index >= size {
panic!(r#"source index (is {source_index:?}) should be < len (is {size:?})"#)
}
return self;
};
}
let (source, target) =
if source_index <= target_index { (source_index, target_index) } else { (target_index, source_index) };
let mut iterator = self.into_iter();
Expand Down
8 changes: 4 additions & 4 deletions src/extensions/collections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ impl<Item> Sequence<Item> for Vec<Item> {
}

fn move_at(mut self, source_index: usize, target_index: usize) -> Self {
if source_index != target_index {
let item = self.remove(source_index);
self.insert(target_index, item);
} else {
if source_index == target_index {
let size = self.len();
if source_index >= size {
panic!(r#"source index (is {source_index:?}) should be < len (is {size:?})"#)
}
} else {
let item = self.remove(source_index);
self.insert(target_index, item);
};
self
}
Expand Down
8 changes: 3 additions & 5 deletions src/extensions/collections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,13 @@ impl<Item> Sequence<Item> for VecDeque<Item> {
}

fn move_at(mut self, source_index: usize, target_index: usize) -> Self {
if source_index != target_index {
if let Some(item) = self.remove(source_index) {
self.insert(target_index, item);
}
} else {
if source_index == target_index {
let size = self.len();
if source_index >= size {
panic!(r#"source index (is {source_index:?}) should be < len (is {size:?})"#)
}
} else if let Some(item) = self.remove(source_index) {
self.insert(target_index, item);
};
self
}
Expand Down

0 comments on commit 2761dce

Please sign in to comment.