artifacts: implement merge()
This commit is contained in:
+31
-2
@@ -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);
|
||||||
|
},
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user