From cac18227340408d6272fefe16d12b6984b79dfce Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Tue, 9 Jun 2026 23:34:30 +0200 Subject: [PATCH] artifacts: implement merge() --- src/artifacts.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/artifacts.rs b/src/artifacts.rs index 39ebe55..aac92a3 100644 --- a/src/artifacts.rs +++ b/src/artifacts.rs @@ -85,9 +85,38 @@ pub enum Artifact { Track(Track) } -impl Artifact { - pub fn merge(&mut self, other: &Artifact) { +macro_rules! merge_fields { + ($this:expr, $that:expr, $field:tt) => { + if $this.$field.is_none() { + $this.$field = $that.$field; + } + }; + ($this:tt, $that:tt, $($fields:tt),+) => { + $( + merge_fields!($this, $that, $fields); + )+ + } +} +impl Artifact { + pub fn merge(&mut self, other: Artifact) { + if *self != other { + return; + } + + match (self, other) { + (Artifact::Track(this_track), Artifact::Track(that_track)) => { + merge_fields!(this_track, that_track, album, label, year, artist, bpm); + // FIXME: genres + }, + (Artifact::Album(this_album), Artifact::Album(that_album)) => { + merge_fields!(this_album, that_album, about, credits, release_date); + }, + (Artifact::Artist(this_artist), Artifact::Artist(that_artist)) => { + merge_fields!(this_artist, that_artist, bio, location); + }, + _ => () + } } }