From aabb4076ff84d2d90b79269b75ab4fafd2dc2e5d Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Wed, 10 May 2023 22:21:31 +0200 Subject: [PATCH] Append I to interface traits --- src/database/json/mod.rs | 4 ++-- src/database/mod.rs | 2 +- src/lib.rs | 20 ++++++++++---------- src/library/beets/mod.rs | 4 ++-- src/library/mod.rs | 2 +- src/main.rs | 6 +++--- src/tui/lib.rs | 4 ++-- tests/database/json.rs | 2 +- tests/library/beets.rs | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/database/json/mod.rs b/src/database/json/mod.rs index 0398292..475d7e5 100644 --- a/src/database/json/mod.rs +++ b/src/database/json/mod.rs @@ -6,7 +6,7 @@ use serde::Serialize; #[cfg(test)] use mockall::automock; -use super::{Database, Error}; +use super::{Error, IDatabase}; pub mod backend; @@ -39,7 +39,7 @@ impl JsonDatabase { } } -impl Database for JsonDatabase { +impl IDatabase for JsonDatabase { fn read(&self, collection: &mut D) -> Result<(), Error> { let serialized = self.backend.read()?; *collection = serde_json::from_str(&serialized)?; diff --git a/src/database/mod.rs b/src/database/mod.rs index 8434b7b..02852df 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -38,7 +38,7 @@ impl From for Error { /// Trait for interacting with the database. #[cfg_attr(test, automock)] -pub trait Database { +pub trait IDatabase { /// Read collection from the database. fn read(&self, collection: &mut D) -> Result<(), Error>; diff --git a/src/lib.rs b/src/lib.rs index 586f3b4..e01004a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ pub mod library; use std::fmt; -use database::Database; -use library::{Library, Query}; +use database::IDatabase; +use library::{ILibrary, Query}; use serde::{Deserialize, Serialize}; use uuid::Uuid; @@ -99,7 +99,7 @@ pub struct MusicHoard { collection: Collection, } -impl MusicHoard { +impl MusicHoard { /// Create a new [`MusicHoard`] with the provided [`Library`] and [`Database`]. pub fn new(library: LIB, database: DB) -> Self { MusicHoard { @@ -133,7 +133,7 @@ mod tests { use mockall::predicate; use once_cell::sync::Lazy; - use crate::{database::MockDatabase, library::MockLibrary}; + use crate::{database::MockIDatabase, library::MockILibrary}; use super::*; @@ -141,8 +141,8 @@ mod tests { #[test] fn read_get_write() { - let mut library = MockLibrary::new(); - let mut database = MockDatabase::new(); + let mut library = MockILibrary::new(); + let mut database = MockIDatabase::new(); let library_input = Query::new(); let library_result = Ok(COLLECTION.to_owned()); @@ -171,8 +171,8 @@ mod tests { #[test] fn library_error() { - let mut library = MockLibrary::new(); - let database = MockDatabase::new(); + let mut library = MockILibrary::new(); + let database = MockIDatabase::new(); let library_result = Err(library::Error::Invalid(String::from("invalid data"))); @@ -193,8 +193,8 @@ mod tests { #[test] fn database_error() { - let library = MockLibrary::new(); - let mut database = MockDatabase::new(); + let library = MockILibrary::new(); + let mut database = MockIDatabase::new(); let database_result = Err(database::Error::IoError(String::from("I/O error"))); diff --git a/src/library/beets/mod.rs b/src/library/beets/mod.rs index d066ea0..9a15fec 100644 --- a/src/library/beets/mod.rs +++ b/src/library/beets/mod.rs @@ -11,7 +11,7 @@ use mockall::automock; use crate::{Album, AlbumId, Artist, ArtistId, Track, TrackFormat}; -use super::{Error, Field, Library, Query}; +use super::{Error, Field, ILibrary, Query}; pub mod executor; @@ -101,7 +101,7 @@ impl BeetsLibrary { } } -impl Library for BeetsLibrary { +impl ILibrary for BeetsLibrary { fn list(&mut self, query: &Query) -> Result, Error> { let cmd = Self::list_cmd_and_args(query); let output = self.executor.exec(&cmd)?; diff --git a/src/library/mod.rs b/src/library/mod.rs index e73eb14..6260682 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -105,7 +105,7 @@ impl From for Error { /// Trait for interacting with the music library. #[cfg_attr(test, automock)] -pub trait Library { +pub trait ILibrary { /// List lirbary items that match the a specific query. fn list(&mut self, query: &Query) -> Result, Error>; } diff --git a/src/main.rs b/src/main.rs index ff4dd14..1dfb7e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,14 +7,14 @@ use structopt::StructOpt; use musichoard::{ database::{ json::{backend::JsonDatabaseFileBackend, JsonDatabase}, - Database, + IDatabase, }, library::{ beets::{ executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor}, BeetsLibrary, }, - Library, + ILibrary, }, MusicHoard, }; @@ -39,7 +39,7 @@ struct Opt { database_file_path: PathBuf, } -fn with(lib: LIB, db: DB) { +fn with(lib: LIB, db: DB) { let music_hoard = MusicHoard::new(lib, db); // Initialize the terminal user interface. diff --git a/src/tui/lib.rs b/src/tui/lib.rs index b503cbb..89a6242 100644 --- a/src/tui/lib.rs +++ b/src/tui/lib.rs @@ -1,4 +1,4 @@ -use musichoard::{MusicHoard, library::Library, database::Database, Collection}; +use musichoard::{database::IDatabase, library::ILibrary, Collection, MusicHoard}; #[cfg(test)] use mockall::automock; @@ -18,7 +18,7 @@ impl From for Error { } // GRCOV_EXCL_START -impl IMusicHoard for MusicHoard { +impl IMusicHoard for MusicHoard { fn rescan_library(&mut self) -> Result<(), Error> { Ok(MusicHoard::rescan_library(self)?) } diff --git a/tests/database/json.rs b/tests/database/json.rs index 55ea7a6..07fbdf6 100644 --- a/tests/database/json.rs +++ b/tests/database/json.rs @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf}; use musichoard::{ database::{ json::{backend::JsonDatabaseFileBackend, JsonDatabase}, - Database, + IDatabase, }, Artist, }; diff --git a/tests/library/beets.rs b/tests/library/beets.rs index 3d9215c..eb8f5f6 100644 --- a/tests/library/beets.rs +++ b/tests/library/beets.rs @@ -9,7 +9,7 @@ use once_cell::sync::Lazy; use musichoard::{ library::{ beets::{executor::BeetsLibraryProcessExecutor, BeetsLibrary}, - Field, Library, Query, + Field, ILibrary, Query, }, Artist, };