Prefer into_iter over drain
All checks were successful
Cargo CI / Build and Test (pull_request) Successful in 1m59s
Cargo CI / Lint (pull_request) Successful in 1m7s

This commit is contained in:
Wojciech Kozlowski 2025-01-02 15:24:45 +01:00
parent edac12ada8
commit 14ab109197
2 changed files with 6 additions and 6 deletions

View File

@ -72,10 +72,10 @@ impl Artist {
fn merge_albums_by_lib_id( fn merge_albums_by_lib_id(
primary_albums: &mut [Album], primary_albums: &mut [Album],
mut secondary_albums: Vec<Album>, secondary_albums: Vec<Album>,
) -> HashMap<String, Vec<Album>> { ) -> HashMap<String, Vec<Album>> {
let mut secondary_without_id = HashMap::<String, Vec<Album>>::new(); let mut secondary_without_id = HashMap::<String, Vec<Album>>::new();
for secondary_album in secondary_albums.drain(..) { for secondary_album in secondary_albums.into_iter() {
let unmerged = Artist::merge_album_by_lib_id(primary_albums, secondary_album); let unmerged = Artist::merge_album_by_lib_id(primary_albums, secondary_album);
if let Some(secondary_album) = unmerged { if let Some(secondary_album) = unmerged {
secondary_without_id secondary_without_id
@ -89,9 +89,9 @@ impl Artist {
fn merge_albums_by_title( fn merge_albums_by_title(
primary_albums: &mut Vec<Album>, primary_albums: &mut Vec<Album>,
mut secondary_without_id: HashMap<String, Vec<Album>>, secondary_without_id: HashMap<String, Vec<Album>>,
) { ) {
for (title, mut secondary_albums) in secondary_without_id.drain() { for (title, mut secondary_albums) in secondary_without_id.into_iter() {
let mut iter = primary_albums.iter_mut(); let mut iter = primary_albums.iter_mut();
match iter.find(|album| album.meta.id.title == title) { match iter.find(|album| album.meta.id.title == title) {
Some(ref mut primary_album) => { Some(ref mut primary_album) => {

View File

@ -23,8 +23,8 @@ impl<T: Ord> Merge for Vec<T> {
} }
impl<K: Hash + PartialEq + Eq, T: Ord> Merge for HashMap<K, Vec<T>> { impl<K: Hash + PartialEq + Eq, T: Ord> Merge for HashMap<K, Vec<T>> {
fn merge_in_place(&mut self, mut other: Self) { fn merge_in_place(&mut self, other: Self) {
for (other_key, other_value) in other.drain() { for (other_key, other_value) in other.into_iter() {
if let Some(ref mut value) = self.get_mut(&other_key) { if let Some(ref mut value) = self.get_mut(&other_key) {
value.merge_in_place(other_value) value.merge_in_place(other_value)
} else { } else {