diff --git a/src/core/musichoard/database.rs b/src/core/musichoard/database.rs index 26a0b71..d73b817 100644 --- a/src/core/musichoard/database.rs +++ b/src/core/musichoard/database.rs @@ -170,15 +170,10 @@ impl IMusicHoardDatabase for MusicHoard Result<(), Error> { - self.update_album_and( - artist_id.as_ref(), - album_id.as_ref(), - |album| { - mem::swap(&mut album.meta.info, &mut info); - album.meta.info.merge_in_place(info); - }, - |artist| artist.albums.sort_unstable(), - ) + self.update_album_and_sort(artist_id.as_ref(), album_id.as_ref(), |album| { + mem::swap(&mut album.meta.info, &mut info); + album.meta.info.merge_in_place(info); + }) } fn clear_album_info, AlbumIdRef: AsRef>( @@ -186,12 +181,9 @@ impl IMusicHoardDatabase for MusicHoard Result<(), Error> { - self.update_album_and( - artist_id.as_ref(), - album_id.as_ref(), - |album| album.meta.info = AlbumInfo::default(), - |artist| artist.albums.sort_unstable(), - ) + self.update_album_and_sort(artist_id.as_ref(), album_id.as_ref(), |album| { + album.meta.info = AlbumInfo::default() + }) } } @@ -270,6 +262,20 @@ impl MusicHoard { self.update_collection(|_| {}) } + fn update_album_and_sort( + &mut self, + artist_id: &ArtistId, + album_id: &AlbumId, + fn_album: FnAlbum, + ) -> Result<(), Error> + where + FnAlbum: FnOnce(&mut Album), + { + self.update_album_and(artist_id, album_id, fn_album, |artist| { + artist.albums.sort_unstable() + }) + } + fn update_album( &mut self, artist_id: &ArtistId,