Hide methods

This commit is contained in:
Wojciech Kozlowski 2024-03-09 22:23:02 +01:00
parent 355446a28b
commit b8e1a771c8
7 changed files with 53 additions and 20 deletions

View File

@ -7,17 +7,45 @@ use crate::core::{
musichoard::{Error, MusicHoard},
};
impl<Database, Library> MusicHoard<Database, Library> {
/// Retrieve the [`Collection`].
pub fn get_collection(&self) -> &Collection {
pub trait IMusicHoardBase {
fn get_collection(&self) -> &Collection;
}
impl<Database, Library> IMusicHoardBase for MusicHoard<Database, Library> {
fn get_collection(&self) -> &Collection {
&self.collection
}
}
pub fn sort_artists(collection: &mut [Artist]) {
pub trait IMusicHoardBasePrivate {
fn sort_artists(collection: &mut [Artist]);
fn sort_albums_and_tracks<'a, C: Iterator<Item = &'a mut Artist>>(collection: C);
fn merge_collections(&self) -> Collection;
fn get_artist<'a>(collection: &'a Collection, artist_id: &ArtistId) -> Option<&'a Artist>;
fn get_artist_mut<'a>(
collection: &'a mut Collection,
artist_id: &ArtistId,
) -> Option<&'a mut Artist>;
fn get_artist_mut_or_err<'a>(
collection: &'a mut Collection,
artist_id: &ArtistId,
) -> Result<&'a mut Artist, Error>;
fn get_album_mut<'a>(artist: &'a mut Artist, album_id: &AlbumId) -> Option<&'a mut Album>;
fn get_album_mut_or_err<'a>(
artist: &'a mut Artist,
album_id: &AlbumId,
) -> Result<&'a mut Album, Error>;
}
impl<Database, Library> IMusicHoardBasePrivate for MusicHoard<Database, Library> {
fn sort_artists(collection: &mut [Artist]) {
collection.sort_unstable();
}
pub fn sort_albums_and_tracks<'a, COL: Iterator<Item = &'a mut Artist>>(collection: COL) {
fn sort_albums_and_tracks<'a, COL: Iterator<Item = &'a mut Artist>>(collection: COL) {
for artist in collection {
artist.albums.sort_unstable();
for album in artist.albums.iter_mut() {
@ -26,22 +54,22 @@ impl<Database, Library> MusicHoard<Database, Library> {
}
}
pub fn merge_collections(&self) -> Collection {
fn merge_collections(&self) -> Collection {
MergeCollections::merge(self.library_cache.clone(), self.database_cache.clone())
}
pub fn get_artist<'a>(collection: &'a Collection, artist_id: &ArtistId) -> Option<&'a Artist> {
fn get_artist<'a>(collection: &'a Collection, artist_id: &ArtistId) -> Option<&'a Artist> {
collection.iter().find(|a| &a.id == artist_id)
}
pub fn get_artist_mut<'a>(
fn get_artist_mut<'a>(
collection: &'a mut Collection,
artist_id: &ArtistId,
) -> Option<&'a mut Artist> {
collection.iter_mut().find(|a| &a.id == artist_id)
}
pub fn get_artist_mut_or_err<'a>(
fn get_artist_mut_or_err<'a>(
collection: &'a mut Collection,
artist_id: &ArtistId,
) -> Result<&'a mut Artist, Error> {
@ -50,11 +78,11 @@ impl<Database, Library> MusicHoard<Database, Library> {
})
}
pub fn get_album_mut<'a>(artist: &'a mut Artist, album_id: &AlbumId) -> Option<&'a mut Album> {
fn get_album_mut<'a>(artist: &'a mut Artist, album_id: &AlbumId) -> Option<&'a mut Album> {
artist.albums.iter_mut().find(|a| &a.id == album_id)
}
pub fn get_album_mut_or_err<'a>(
fn get_album_mut_or_err<'a>(
artist: &'a mut Artist,
album_id: &AlbumId,
) -> Result<&'a mut Album, Error> {

View File

@ -6,7 +6,7 @@ use crate::core::{
Collection,
},
interface::database::IDatabase,
musichoard::{Error, MusicHoard, NoDatabase},
musichoard::{base::IMusicHoardBasePrivate, Error, MusicHoard, NoDatabase},
};
impl<Library> MusicHoard<NoDatabase, Library> {
@ -227,7 +227,7 @@ mod tests {
use crate::core::{
collection::{album::AlbumDate, artist::ArtistId, musicbrainz::MusicBrainzUrl},
interface::database::{self, MockIDatabase},
musichoard::NoLibrary,
musichoard::{base::IMusicHoardBase, NoLibrary},
testmod::FULL_COLLECTION,
};

View File

@ -11,7 +11,7 @@ use crate::core::{
database::IDatabase,
library::{ILibrary, Item, Query},
},
musichoard::{Error, MusicHoard, NoDatabase},
musichoard::{base::IMusicHoardBasePrivate, Error, MusicHoard, NoDatabase},
};
impl<Library: ILibrary> MusicHoard<NoDatabase, Library> {
@ -124,6 +124,7 @@ mod tests {
database::MockIDatabase,
library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
},
musichoard::base::IMusicHoardBase,
testmod::LIBRARY_COLLECTION,
};

View File

@ -6,6 +6,8 @@ mod library;
pub mod builder;
pub use base::IMusicHoardBase;
use std::{
collections::HashMap,
fmt::{self, Display},

View File

@ -7,7 +7,9 @@ pub mod library;
pub use core::collection;
pub use core::interface;
pub use core::musichoard::{builder::MusicHoardBuilder, Error, MusicHoard, NoDatabase, NoLibrary};
pub use core::musichoard::{
builder::MusicHoardBuilder, Error, IMusicHoardBase, MusicHoard, NoDatabase, NoLibrary,
};
#[cfg(test)]
#[macro_use]

View File

@ -1,6 +1,6 @@
use musichoard::{
collection::Collection, interface::database::IDatabase, interface::library::ILibrary,
MusicHoard,
IMusicHoardBase, MusicHoard,
};
#[cfg(test)]
@ -16,15 +16,15 @@ pub trait IMusicHoard {
// GRCOV_EXCL_START
impl<Database: IDatabase, Library: ILibrary> IMusicHoard for MusicHoard<Database, Library> {
fn rescan_library(&mut self) -> Result<(), musichoard::Error> {
MusicHoard::<Database, Library>::rescan_library(self)
Self::rescan_library(self)
}
fn reload_database(&mut self) -> Result<(), musichoard::Error> {
MusicHoard::reload_database(self)
Self::reload_database(self)
}
fn get_collection(&self) -> &Collection {
MusicHoard::get_collection(self)
<Self as IMusicHoardBase>::get_collection(self)
}
}
// GRCOV_EXCL_STOP

View File

@ -9,7 +9,7 @@ mod testlib;
use musichoard::{
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary},
MusicHoard,
IMusicHoardBase, MusicHoard,
};
use crate::testlib::COLLECTION;