Replace as many Box<dyn Trait> with generics as possible #32

Merged
wojtek merged 7 commits from 31---replace-as-many-Box-dyn-trait-with-generics-as-possible into main 2023-04-13 15:29:14 +02:00
2 changed files with 9 additions and 9 deletions
Showing only changes of commit ea736cebed - Show all commits

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());