Streamline adding new URL types #122
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, BTreeMap},
|
collections::{BTreeMap, HashMap},
|
||||||
fmt::{self, Debug, Display},
|
fmt::{self, Debug, Display},
|
||||||
mem,
|
mem,
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{cmp::Ordering, iter::Peekable, collections::HashMap, hash::Hash};
|
use std::{cmp::Ordering, collections::HashMap, hash::Hash, iter::Peekable};
|
||||||
|
|
||||||
/// A trait for merging two objects. The merge is asymmetric with the left argument considered to be
|
/// A trait for merging two objects. The merge is asymmetric with the left argument considered to be
|
||||||
/// the primary whose properties are to be kept in case of collisions.
|
/// the primary whose properties are to be kept in case of collisions.
|
||||||
|
@ -124,9 +124,9 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Ok(self
|
self.get_artist_mut_or_err(artist_id.as_ref())?
|
||||||
.get_artist_mut_or_err(artist_id.as_ref())?
|
.clear_musicbrainz_url();
|
||||||
.clear_musicbrainz_url())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_to_property<ID: AsRef<ArtistId>, S: AsRef<str> + Into<String>>(
|
pub fn add_to_property<ID: AsRef<ArtistId>, S: AsRef<str> + Into<String>>(
|
||||||
@ -135,9 +135,9 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
|||||||
property: S,
|
property: S,
|
||||||
values: Vec<S>,
|
values: Vec<S>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Ok(self
|
self.get_artist_mut_or_err(artist_id.as_ref())?
|
||||||
.get_artist_mut_or_err(artist_id.as_ref())?
|
.add_to_property(property, values);
|
||||||
.add_to_property(property, values))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_from_property<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn remove_from_property<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
@ -146,9 +146,9 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
|||||||
property: S,
|
property: S,
|
||||||
values: Vec<S>,
|
values: Vec<S>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Ok(self
|
self.get_artist_mut_or_err(artist_id.as_ref())?
|
||||||
.get_artist_mut_or_err(artist_id.as_ref())?
|
.remove_from_property(property, values);
|
||||||
.remove_from_property(property, values))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_property<ID: AsRef<ArtistId>, S: AsRef<str> + Into<String>>(
|
pub fn set_property<ID: AsRef<ArtistId>, S: AsRef<str> + Into<String>>(
|
||||||
@ -157,9 +157,9 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
|||||||
property: S,
|
property: S,
|
||||||
values: Vec<S>,
|
values: Vec<S>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Ok(self
|
self.get_artist_mut_or_err(artist_id.as_ref())?
|
||||||
.get_artist_mut_or_err(artist_id.as_ref())?
|
.set_property(property, values);
|
||||||
.set_property(property, values))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_property<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
pub fn clear_property<ID: AsRef<ArtistId>, S: AsRef<str>>(
|
||||||
@ -167,9 +167,9 @@ impl<LIB, DB> MusicHoard<LIB, DB> {
|
|||||||
artist_id: ID,
|
artist_id: ID,
|
||||||
property: S,
|
property: S,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
Ok(self
|
self.get_artist_mut_or_err(artist_id.as_ref())?
|
||||||
.get_artist_mut_or_err(artist_id.as_ref())?
|
.clear_property(property);
|
||||||
.clear_property(property))
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sort(collection: &mut [Artist]) {
|
fn sort(collection: &mut [Artist]) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
use musichoard::collection::{
|
use musichoard::collection::{
|
||||||
album::{Album, AlbumId},
|
album::{Album, AlbumId},
|
||||||
artist::{Artist, ArtistId, MusicBrainz},
|
artist::{Artist, ArtistId, MusicBrainz},
|
||||||
track::{Format, Quality, Track, TrackId},
|
track::{Format, Quality, Track, TrackId},
|
||||||
};
|
};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::tests::*;
|
use crate::tests::*;
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ impl<'a> ArtistOverlay<'a> {
|
|||||||
list_indent: &str,
|
list_indent: &str,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut vec: Vec<(&str, &Vec<T>)> = map.iter().map(|(k, v)| (k.as_ref(), v)).collect();
|
let mut vec: Vec<(&str, &Vec<T>)> = map.iter().map(|(k, v)| (k.as_ref(), v)).collect();
|
||||||
vec.sort_by(|x, y| x.0.cmp(&y.0));
|
vec.sort_by(|x, y| x.0.cmp(y.0));
|
||||||
|
|
||||||
let indent = format!("\n{item_indent}");
|
let indent = format!("\n{item_indent}");
|
||||||
let list = vec
|
let list = vec
|
||||||
|
Loading…
Reference in New Issue
Block a user