More explicit conversion
Some checks failed
Cargo CI / Lint (pull_request) Has been cancelled
Cargo CI / Build and Test (pull_request) Has been cancelled

This commit is contained in:
Wojciech Kozlowski 2024-08-31 22:50:01 +02:00
parent 563782f82d
commit e8b5532a1b
3 changed files with 35 additions and 35 deletions

View File

@ -158,6 +158,16 @@ mod tests {
use super::*; use super::*;
impl<T> Match<T> {
pub fn new(score: u8, item: T) -> Self {
Match {
score,
item,
disambiguation: None,
}
}
}
fn artist_matches_info_vec() -> Vec<AppMatchesInfo> { fn artist_matches_info_vec() -> Vec<AppMatchesInfo> {
let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1")); let artist_1 = ArtistMeta::new(ArtistId::new("Artist 1"));
@ -166,7 +176,7 @@ mod tests {
let artist_1_2 = artist_1.clone(); let artist_1_2 = artist_1.clone();
let mut artist_match_1_2 = Match::new(100, artist_1_2); let mut artist_match_1_2 = Match::new(100, artist_1_2);
artist_match_1_2.set_disambiguation("some disambiguation"); artist_match_1_2.disambiguation = Some(String::from("some disambiguation"));
let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()]; let list = vec![artist_match_1_1.clone(), artist_match_1_2.clone()];
let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list); let matches_info_1 = AppMatchesInfo::artist(artist_1.clone(), list);

View File

@ -1,8 +1,10 @@
//! Module for interacting with the [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API). //! Module for interacting with the [MusicBrainz API](https://musicbrainz.org/doc/MusicBrainz_API).
use std::collections::HashMap;
use musichoard::{ use musichoard::{
collection::{ collection::{
album::{AlbumDate, AlbumMeta}, album::{AlbumDate, AlbumMeta, AlbumSeq},
artist::ArtistMeta, artist::ArtistMeta,
musicbrainz::Mbid, musicbrainz::Mbid,
}, },
@ -71,30 +73,32 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
} }
fn from_search_artist_response_artist(entity: SearchArtistResponseArtist) -> Match<ArtistMeta> { fn from_search_artist_response_artist(entity: SearchArtistResponseArtist) -> Match<ArtistMeta> {
let mut artist = ArtistMeta::new(entity.name); Match {
if let Some(sort) = entity.sort { score: entity.score,
artist.set_sort_key(sort); item: ArtistMeta {
id: entity.name.into(),
sort: entity.sort.map(Into::into),
musicbrainz: Some(entity.id.into()),
properties: HashMap::new(),
},
disambiguation: entity.disambiguation,
} }
artist.set_musicbrainz_ref(entity.id.into());
let mut artist_match = Match::new(entity.score, artist);
if let Some(disambiguation) = entity.disambiguation {
artist_match.set_disambiguation(disambiguation);
}
artist_match
} }
fn from_search_release_group_response_release_group( fn from_search_release_group_response_release_group(
entity: SearchReleaseGroupResponseReleaseGroup, entity: SearchReleaseGroupResponseReleaseGroup,
) -> Match<AlbumMeta> { ) -> Match<AlbumMeta> {
let mut album = AlbumMeta::new( Match {
entity.title, score: entity.score,
entity.first_release_date, item: AlbumMeta {
Some(entity.primary_type), id: entity.title.into(),
entity.secondary_types.unwrap_or_default(), date: entity.first_release_date,
); seq: AlbumSeq::default(),
album.set_musicbrainz_ref(entity.id.into()); musicbrainz: Some(entity.id.into()),
Match::new(entity.score, album) primary_type: Some(entity.primary_type),
secondary_types: entity.secondary_types.unwrap_or_default(),
},
disambiguation: None,
}
} }
// GRCOV_EXCL_STOP // GRCOV_EXCL_STOP

View File

@ -23,18 +23,4 @@ pub struct Match<T> {
pub disambiguation: Option<String>, pub disambiguation: Option<String>,
} }
impl<T> Match<T> {
pub fn new(score: u8, item: T) -> Self {
Match {
score,
item,
disambiguation: None,
}
}
pub fn set_disambiguation<S: Into<String>>(&mut self, disambiguation: S) {
self.disambiguation = Some(disambiguation.into())
}
}
pub type Error = musichoard::external::musicbrainz::api::Error; pub type Error = musichoard::external::musicbrainz::api::Error;