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
10 changed files with 19 additions and 30 deletions
Showing only changes of commit 93d8ba8cb2 - Show all commits

View File

@ -1,8 +1,5 @@
//! Module for interacting with the music library. //! Module for interacting with the music library.
#[cfg(feature = "library-beets")]
pub mod beets;
use std::{collections::HashSet, fmt, num::ParseIntError, str::Utf8Error}; use std::{collections::HashSet, fmt, num::ParseIntError, str::Utf8Error};
#[cfg(test)] #[cfg(test)]
@ -59,26 +56,16 @@ pub enum Field {
} }
/// A library query. Can include or exclude particular fields. /// A library query. Can include or exclude particular fields.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct Query { pub struct Query {
include: HashSet<Field>, pub include: HashSet<Field>,
exclude: HashSet<Field>, pub exclude: HashSet<Field>,
}
impl Default for Query {
/// Create an empty query.
fn default() -> Self {
Self::new()
}
} }
impl Query { impl Query {
/// Create an empty query. /// Create an empty query.
pub fn new() -> Self { pub fn new() -> Self {
Query { Query::default()
include: HashSet::new(),
exclude: HashSet::new(),
}
} }
/// Refine the query to include a particular search term. /// Refine the query to include a particular search term.

View File

@ -2,11 +2,13 @@
mod core; mod core;
pub mod database; pub mod database;
pub mod library;
pub use core::collection; pub use core::collection;
pub use core::library;
// TODO: evaluate the exports and/or how to do them
pub use core::database::{IDatabase, NullDatabase}; 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,8 @@ use std::{
str, str,
}; };
use crate::core::library::{beets::IBeetsLibraryExecutor, Error}; use crate::core::library::Error;
use crate::library::beets::IBeetsLibraryExecutor;
const BEET_DEFAULT: &str = "beet"; const BEET_DEFAULT: &str = "beet";

2
src/library/mod.rs Normal file
View File

@ -0,0 +1,2 @@
#[cfg(feature = "library-beets")]
pub mod beets;

View File

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

View File

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

View File

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

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},
library::Item, Item,
}; };
pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> { pub static LIBRARY_ITEMS: Lazy<Vec<Item>> = Lazy::new(|| -> Vec<Item> {