Missing docstrings #102

Merged
wojtek merged 1 commits from 98---missing-docstrings into main 2024-01-12 21:52:06 +01:00
3 changed files with 17 additions and 2 deletions
Showing only changes of commit f9971fe6ff - Show all commits

View File

@ -29,6 +29,7 @@ pub trait IMbid {
fn mbid(&self) -> &str; fn mbid(&self) -> &str;
} }
/// The different URL types supported by MusicHoard.
#[derive(Debug)] #[derive(Debug)]
enum UrlType { enum UrlType {
MusicBrainz, MusicBrainz,
@ -37,6 +38,7 @@ enum UrlType {
Qobuz, Qobuz,
} }
/// Invalid URL error.
struct InvalidUrlError { struct InvalidUrlError {
url_type: UrlType, url_type: UrlType,
url: String, url: String,
@ -53,6 +55,7 @@ impl Display for InvalidUrlError {
pub struct MusicBrainz(Url); pub struct MusicBrainz(Url);
impl MusicBrainz { impl MusicBrainz {
/// Validate and wrap a MusicBrainz URL.
pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> { pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> {
let url = Url::parse(url.as_ref())?; let url = Url::parse(url.as_ref())?;
@ -112,6 +115,7 @@ impl IMbid for MusicBrainz {
pub struct MusicButler(Url); pub struct MusicButler(Url);
impl MusicButler { impl MusicButler {
/// Validate and wrap a MusicButler URL.
pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> { pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> {
let url = Url::parse(url.as_ref())?; let url = Url::parse(url.as_ref())?;
@ -157,6 +161,7 @@ impl IUrl for MusicButler {
pub struct Bandcamp(Url); pub struct Bandcamp(Url);
impl Bandcamp { impl Bandcamp {
/// Validate and wrap a Bandcamp URL.
pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> { pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> {
let url = Url::parse(url.as_ref())?; let url = Url::parse(url.as_ref())?;
@ -202,6 +207,7 @@ impl IUrl for Bandcamp {
pub struct Qobuz(Url); pub struct Qobuz(Url);
impl Qobuz { impl Qobuz {
/// Validate and wrap a Qobuz URL.
pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> { pub fn new<S: AsRef<str>>(url: S) -> Result<Self, Error> {
let url = Url::parse(url.as_ref())?; let url = Url::parse(url.as_ref())?;
@ -423,6 +429,7 @@ macro_rules! artist_multi_url_dispatch {
} }
impl Artist { impl Artist {
/// Create new [`Artist`] with the given [`ArtistId`].
pub fn new<ID: Into<ArtistId>>(id: ID) -> Self { pub fn new<ID: Into<ArtistId>>(id: ID) -> Self {
Artist { Artist {
id: id.into(), id: id.into(),
@ -698,8 +705,10 @@ pub struct MusicHoard<LIB, DB> {
database: DB, database: DB,
} }
// Unit structs to ensure library/database are not compiled in. /// Phantom type for when a library implementation is not needed.
pub struct NoLibrary; pub struct NoLibrary;
/// Phantom type for when a database implementation is not needed.
pub struct NoDatabase; pub struct NoDatabase;
macro_rules! music_hoard_unique_url_dispatch { macro_rules! music_hoard_unique_url_dispatch {
@ -787,6 +796,7 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
} }
} }
/// Retrieve the [`Collection`].
pub fn get_collection(&self) -> &Collection { pub fn get_collection(&self) -> &Collection {
&self.collection &self.collection
} }
@ -914,6 +924,7 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
} }
impl<LIB: ILibrary, DB> MusicHoard<LIB, DB> { impl<LIB: ILibrary, DB> MusicHoard<LIB, DB> {
/// Rescan the library and merge with the in-memory collection.
pub fn rescan_library(&mut self) -> Result<(), Error> { pub fn rescan_library(&mut self) -> Result<(), Error> {
let items = self.library.list(&Query::new())?; let items = self.library.list(&Query::new())?;
let mut library_collection = Self::items_to_artists(items); let mut library_collection = Self::items_to_artists(items);
@ -927,6 +938,7 @@ impl<LIB: ILibrary, DB> MusicHoard<LIB, DB> {
} }
impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> { impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
/// Load the database and merge with the in-memory collection.
pub fn load_from_database(&mut self) -> Result<(), Error> { pub fn load_from_database(&mut self) -> Result<(), Error> {
let mut database_collection = self.database.load()?; let mut database_collection = self.database.load()?;
Self::sort(&mut database_collection); Self::sort(&mut database_collection);
@ -937,6 +949,7 @@ impl<LIB, DB: IDatabase> MusicHoard<LIB, DB> {
Ok(()) Ok(())
} }
/// Save the in-memory collection to the database.
pub fn save_to_database(&mut self) -> Result<(), Error> { pub fn save_to_database(&mut self) -> Result<(), Error> {
self.database.save(&self.collection)?; self.database.save(&self.collection)?;
Ok(()) Ok(())

View File

@ -76,6 +76,8 @@ impl IBeetsLibraryExecutorPrivate for BeetsLibraryProcessExecutor {}
// GRCOV_EXCL_START // GRCOV_EXCL_START
#[cfg(feature = "ssh-library")] #[cfg(feature = "ssh-library")]
pub mod ssh { pub mod ssh {
//! Module for interacting with the music library via
//! [beets](https://beets.readthedocs.io/en/stable/) over SSH.
use openssh::{KnownHosts, Session}; use openssh::{KnownHosts, Session};
use tokio::runtime::{self, Runtime}; use tokio::runtime::{self, Runtime};

View File

@ -13,7 +13,7 @@ pub mod beets;
/// Trait for interacting with the music library. /// Trait for interacting with the music library.
#[cfg_attr(test, automock)] #[cfg_attr(test, automock)]
pub trait ILibrary { pub trait ILibrary {
/// List lirbary items that match the a specific query. /// List library items that match the a specific query.
fn list(&mut self, query: &Query) -> Result<Vec<Item>, Error>; fn list(&mut self, query: &Query) -> Result<Vec<Item>, Error>;
} }