Generic beets library
This commit is contained in:
parent
73b4cc8b28
commit
45e65073e9
@ -56,18 +56,15 @@ pub trait CollectionManager {
|
||||
|
||||
/// The collection manager. It is responsible for pulling information from both the library and the
|
||||
/// database, ensuring its consistent and writing back any changes.
|
||||
pub struct MhCollectionManager {
|
||||
library: Box<dyn Library + Send + Sync>,
|
||||
pub struct MhCollectionManager<L> {
|
||||
library: L,
|
||||
database: Box<dyn Database + Send + Sync>,
|
||||
collection: Collection,
|
||||
}
|
||||
|
||||
impl MhCollectionManager {
|
||||
impl<L: Library> MhCollectionManager<L> {
|
||||
/// Create a new [`CollectionManager`] with the provided [`Library`] and [`Database`].
|
||||
pub fn new(
|
||||
library: Box<dyn Library + Send + Sync>,
|
||||
database: Box<dyn Database + Send + Sync>,
|
||||
) -> Self {
|
||||
pub fn new(library: L, database: Box<dyn Database + Send + Sync>) -> Self {
|
||||
MhCollectionManager {
|
||||
library,
|
||||
database,
|
||||
@ -76,7 +73,7 @@ impl MhCollectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectionManager for MhCollectionManager {
|
||||
impl<L: Library> CollectionManager for MhCollectionManager<L> {
|
||||
fn rescan_library(&mut self) -> Result<(), Error> {
|
||||
self.collection = self.library.list(&Query::default())?;
|
||||
Ok(())
|
||||
@ -127,8 +124,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| database_result);
|
||||
|
||||
let mut collection_manager =
|
||||
MhCollectionManager::new(Box::new(library), Box::new(database));
|
||||
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
|
||||
|
||||
collection_manager.rescan_library().unwrap();
|
||||
assert_eq!(collection_manager.get_collection(), &*COLLECTION);
|
||||
@ -147,8 +143,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| library_result);
|
||||
|
||||
let mut collection_manager =
|
||||
MhCollectionManager::new(Box::new(library), Box::new(database));
|
||||
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
|
||||
|
||||
let actual_err = collection_manager.rescan_library().unwrap_err();
|
||||
let expected_err = Error::LibraryError(
|
||||
@ -171,8 +166,7 @@ mod tests {
|
||||
.times(1)
|
||||
.return_once(|_| database_result);
|
||||
|
||||
let mut collection_manager =
|
||||
MhCollectionManager::new(Box::new(library), Box::new(database));
|
||||
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
|
||||
|
||||
let actual_err = collection_manager.save_to_database().unwrap_err();
|
||||
let expected_err =
|
||||
|
@ -49,7 +49,7 @@ fn main() {
|
||||
&opt.database_file_path,
|
||||
)));
|
||||
|
||||
let collection_manager = MhCollectionManager::new(Box::new(beets), Box::new(database));
|
||||
let collection_manager = MhCollectionManager::new(beets, Box::new(database));
|
||||
|
||||
// Initialize the terminal user interface.
|
||||
let backend = CrosstermBackend::new(io::stdout());
|
||||
|
Loading…
Reference in New Issue
Block a user