Generic database

This commit is contained in:
Wojciech Kozlowski 2023-04-13 14:49:44 +02:00
parent 45e65073e9
commit ea736cebed
2 changed files with 9 additions and 9 deletions

View File

@ -56,15 +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<L> {
pub struct MhCollectionManager<L, D> {
library: L,
database: Box<dyn Database + Send + Sync>,
database: D,
collection: Collection,
}
impl<L: Library> MhCollectionManager<L> {
impl<L: Library, D: Database> MhCollectionManager<L, D> {
/// Create a new [`CollectionManager`] with the provided [`Library`] and [`Database`].
pub fn new(library: L, database: Box<dyn Database + Send + Sync>) -> Self {
pub fn new(library: L, database: D) -> Self {
MhCollectionManager {
library,
database,
@ -73,7 +73,7 @@ impl<L: Library> MhCollectionManager<L> {
}
}
impl<L: Library> CollectionManager for MhCollectionManager<L> {
impl<L: Library, D: Database> CollectionManager for MhCollectionManager<L, D> {
fn rescan_library(&mut self) -> Result<(), Error> {
self.collection = self.library.list(&Query::default())?;
Ok(())
@ -124,7 +124,7 @@ mod tests {
.times(1)
.return_once(|_| database_result);
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
let mut collection_manager = MhCollectionManager::new(library, database);
collection_manager.rescan_library().unwrap();
assert_eq!(collection_manager.get_collection(), &*COLLECTION);
@ -143,7 +143,7 @@ mod tests {
.times(1)
.return_once(|_| library_result);
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
let mut collection_manager = MhCollectionManager::new(library, database);
let actual_err = collection_manager.rescan_library().unwrap_err();
let expected_err = Error::LibraryError(
@ -166,7 +166,7 @@ mod tests {
.times(1)
.return_once(|_| database_result);
let mut collection_manager = MhCollectionManager::new(library, Box::new(database));
let mut collection_manager = MhCollectionManager::new(library, database);
let actual_err = collection_manager.save_to_database().unwrap_err();
let expected_err =

View File

@ -49,7 +49,7 @@ fn main() {
&opt.database_file_path,
)));
let collection_manager = MhCollectionManager::new(beets, Box::new(database));
let collection_manager = MhCollectionManager::new(beets, database);
// Initialize the terminal user interface.
let backend = CrosstermBackend::new(io::stdout());