Move database and library implementations out of core #162

Merged
wojtek merged 5 commits from 159---move-database-and-library-implementations-out-of-core into main 2024-03-09 19:12:00 +01:00
18 changed files with 36 additions and 25 deletions
Showing only changes of commit 6178a30353 - Show all commits

View File

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use crate::core::{ use crate::core::{
collection::{album::AlbumMonth, track::TrackFormat}, collection::{album::AlbumMonth, track::TrackFormat},
library::Item, interface::library::Item,
}; };
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> { pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {

View File

@ -0,0 +1,2 @@
pub mod database;
pub mod library;

View File

@ -1,6 +1,5 @@
pub mod collection; pub mod collection;
pub mod database; pub mod interface;
pub mod library;
pub mod musichoard; pub mod musichoard;
#[cfg(test)] #[cfg(test)]

View File

@ -6,7 +6,10 @@ pub mod musichoard_builder;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use crate::core::{collection, database, library}; use crate::core::{
collection,
interface::{database, library},
};
/// Error type for `musichoard`. /// Error type for `musichoard`.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]

View File

@ -8,8 +8,10 @@ use crate::core::{
track::{Track, TrackId, TrackNum, TrackQuality}, track::{Track, TrackId, TrackNum, TrackQuality},
Collection, MergeCollections, Collection, MergeCollections,
}, },
interface::{
database::IDatabase, database::IDatabase,
library::{ILibrary, Item, Query}, library::{ILibrary, Item, Query},
},
musichoard::Error, musichoard::Error,
}; };
@ -468,8 +470,10 @@ mod tests {
use crate::core::{ use crate::core::{
collection::{artist::ArtistId, musicbrainz::MusicBrainz}, collection::{artist::ArtistId, musicbrainz::MusicBrainz},
interface::{
database::{self, MockIDatabase}, database::{self, MockIDatabase},
library::{self, testmod::LIBRARY_ITEMS, MockILibrary}, library::{self, testmod::LIBRARY_ITEMS, MockILibrary},
},
testmod::{FULL_COLLECTION, LIBRARY_COLLECTION}, testmod::{FULL_COLLECTION, LIBRARY_COLLECTION},
}; };

View File

@ -1,7 +1,6 @@
use crate::{ use crate::{
core::{ core::{
database::IDatabase, interface::{database::IDatabase, library::ILibrary},
library::ILibrary,
musichoard::musichoard::{MusicHoard, NoDatabase, NoLibrary}, musichoard::musichoard::{MusicHoard, NoDatabase, NoLibrary},
}, },
Error, Error,
@ -79,7 +78,7 @@ impl<LIB: ILibrary, DB: IDatabase> MusicHoardBuilder<LIB, DB> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::core::{database::NullDatabase, library::NullLibrary}; use crate::core::interface::{database::NullDatabase, library::NullLibrary};
use super::*; use super::*;

View File

@ -7,7 +7,7 @@ use mockall::automock;
use crate::core::{ use crate::core::{
collection::Collection, collection::Collection,
database::{IDatabase, LoadError, SaveError}, interface::database::{IDatabase, LoadError, SaveError},
}; };
use super::serde::{deserialize::DeserializeDatabase, serialize::SerializeDatabase}; use super::serde::{deserialize::DeserializeDatabase, serialize::SerializeDatabase};

View File

@ -9,7 +9,7 @@ use crate::core::{
musicbrainz::MusicBrainz, musicbrainz::MusicBrainz,
Collection, Collection,
}, },
database::LoadError, interface::database::LoadError,
}; };
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View File

@ -5,10 +5,7 @@ pub mod database;
pub mod library; pub mod library;
pub use core::collection; pub use core::collection;
pub use core::interface;
// TODO: evaluate the exports and/or how to do them
pub use core::database::{IDatabase, NullDatabase};
pub use core::library::{Field, ILibrary, Item, NullLibrary, Query};
pub use core::musichoard::{ pub use core::musichoard::{
musichoard::{MusicHoard, NoDatabase, NoLibrary}, musichoard::{MusicHoard, NoDatabase, NoLibrary},

View File

@ -8,7 +8,7 @@ use std::{
str, str,
}; };
use crate::core::library::Error; use crate::core::interface::library::Error;
use crate::library::beets::IBeetsLibraryExecutor; use crate::library::beets::IBeetsLibraryExecutor;
const BEET_DEFAULT: &str = "beet"; const BEET_DEFAULT: &str = "beet";

View File

@ -8,7 +8,7 @@ use mockall::automock;
use crate::core::{ use crate::core::{
collection::track::TrackFormat, collection::track::TrackFormat,
library::{Error, Field, ILibrary, Item, Query}, interface::library::{Error, Field, ILibrary, Item, Query},
}; };
macro_rules! list_format_separator { macro_rules! list_format_separator {
@ -201,7 +201,7 @@ mod testmod;
mod tests { mod tests {
use mockall::predicate; use mockall::predicate;
use crate::{collection::album::AlbumMonth, core::library::testmod::LIBRARY_ITEMS}; use crate::{collection::album::AlbumMonth, core::interface::library::testmod::LIBRARY_ITEMS};
use super::*; use super::*;
use testmod::LIBRARY_BEETS; use testmod::LIBRARY_BEETS;

View File

@ -11,11 +11,15 @@ use structopt::StructOpt;
use musichoard::{ use musichoard::{
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase}, database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
interface::{
database::{IDatabase, NullDatabase},
library::{ILibrary, NullLibrary},
},
library::beets::{ library::beets::{
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor}, executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
BeetsLibrary, BeetsLibrary,
}, },
IDatabase, ILibrary, MusicHoardBuilder, NoDatabase, NoLibrary, NullDatabase, NullLibrary, MusicHoardBuilder, NoDatabase, NoLibrary,
}; };
use tui::{App, EventChannel, EventHandler, EventListener, Tui, Ui}; use tui::{App, EventChannel, EventHandler, EventListener, Tui, Ui};

View File

@ -1,4 +1,7 @@
use musichoard::{collection::Collection, IDatabase, ILibrary, MusicHoard}; use musichoard::{
collection::Collection, interface::database::IDatabase, interface::library::ILibrary,
MusicHoard,
};
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;

View File

@ -6,7 +6,7 @@ use tempfile::NamedTempFile;
use musichoard::{ use musichoard::{
collection::{album::AlbumDate, artist::Artist, Collection}, collection::{album::AlbumDate, artist::Artist, Collection},
database::json::{backend::JsonDatabaseFileBackend, JsonDatabase}, database::json::{backend::JsonDatabaseFileBackend, JsonDatabase},
IDatabase, interface::database::IDatabase,
}; };
use crate::testlib::COLLECTION; use crate::testlib::COLLECTION;

View File

@ -8,8 +8,8 @@ use std::{
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use musichoard::{ use musichoard::{
interface::library::{Field, ILibrary, Item, Query},
library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary}, library::beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary},
Field, ILibrary, Item, Query,
}; };
use crate::library::testmod::LIBRARY_ITEMS; use crate::library::testmod::LIBRARY_ITEMS;

View File

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use musichoard::{ use musichoard::{
collection::{album::AlbumMonth, track::TrackFormat}, collection::{album::AlbumMonth, track::TrackFormat},
Item, interface::library::Item,
}; };
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> { pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {