Break down the musichoard files #165

Merged
wojtek merged 9 commits from 164---break-down-the-musichoard-files into main 2024-03-09 22:52:04 +01:00
6 changed files with 18 additions and 12 deletions
Showing only changes of commit 3fadd109e7 - Show all commits

View File

@ -146,7 +146,10 @@ impl<Database: IDatabase, Library: ILibrary> MusicHoard<Database, Library> {
#[cfg(test)]
mod tests {
use crate::core::interface::{database::NullDatabase, library::NullLibrary};
use crate::core::{
interface::{database::NullDatabase, library::NullLibrary},
musichoard::library::IMusicHoardLibrary,
};
use super::*;

View File

@ -17,17 +17,19 @@ use crate::core::{
},
};
impl<Library: ILibrary> MusicHoard<NoDatabase, Library> {
/// Rescan the library and merge with the in-memory collection.
pub fn rescan_library(&mut self) -> Result<(), Error> {
pub trait IMusicHoardLibrary {
fn rescan_library(&mut self) -> Result<(), Error>;
}
impl<Library: ILibrary> IMusicHoardLibrary for MusicHoard<NoDatabase, Library> {
fn rescan_library(&mut self) -> Result<(), Error> {
self.pre_commit = self.rescan_library_inner()?;
self.commit()
}
}
impl<Database: IDatabase, Library: ILibrary> MusicHoard<Database, Library> {
/// Rescan the library and merge with the in-memory collection.
pub fn rescan_library(&mut self) -> Result<(), Error> {
impl<Database: IDatabase, Library: ILibrary> IMusicHoardLibrary for MusicHoard<Database, Library> {
fn rescan_library(&mut self) -> Result<(), Error> {
self.pre_commit = self.rescan_library_inner()?;
self.commit()
}

View File

@ -8,6 +8,7 @@ pub mod builder;
pub use base::IMusicHoardBase;
pub use database::IMusicHoardDatabase;
pub use library::IMusicHoardLibrary;
use std::{
collections::HashMap,

View File

@ -8,8 +8,8 @@ pub use core::collection;
pub use core::interface;
pub use core::musichoard::{
builder::MusicHoardBuilder, Error, IMusicHoardBase, IMusicHoardDatabase, MusicHoard,
NoDatabase, NoLibrary,
builder::MusicHoardBuilder, Error, IMusicHoardBase, IMusicHoardDatabase, IMusicHoardLibrary,
MusicHoard, NoDatabase, NoLibrary,
};
#[cfg(test)]

View File

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

View File

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