artifacts: implement merge()

This commit is contained in:
2026-06-09 23:34:30 +02:00
parent 45b3ada3e9
commit cac1822734
+31 -2
View File
@@ -85,9 +85,38 @@ pub enum Artifact {
Track(Track) Track(Track)
} }
impl Artifact { macro_rules! merge_fields {
pub fn merge(&mut self, other: &Artifact) { ($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);
},
_ => ()
}
} }
} }