Some code ergonomics
Some checks failed
Cargo CI / Build and Test (pull_request) Failing after 59s
Cargo CI / Lint (pull_request) Successful in 42s

This commit is contained in:
Wojciech Kozlowski 2024-01-08 22:52:50 +01:00
parent d43f82d5ef
commit ac7a86f925

View File

@ -95,6 +95,18 @@ macro_rules! url_command_dispatch {
};
}
macro_rules! single_url_command_dispatch {
($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => {
url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, url)
};
}
macro_rules! multi_url_command_dispatch {
($cmd:ident, $mh:ident, $add:ident, $remove:ident, $set:ident, $clear:ident) => {
url_command_dispatch!($cmd, $mh, $add, $remove, $set, $clear, urls)
};
}
impl ArtistCommand {
fn handle(self, music_hoard: &mut MH) {
match self {
@ -108,41 +120,37 @@ impl ArtistCommand {
.delete_artist(ArtistId::new(artist_value.artist))
.expect("failed to delete artist");
}
ArtistCommand::MusicBrainz(url_command) => url_command_dispatch!(
ArtistCommand::MusicBrainz(url_command) => single_url_command_dispatch!(
url_command,
music_hoard,
add_musicbrainz_url,
remove_musicbrainz_url,
set_musicbrainz_url,
clear_musicbrainz_url,
url
clear_musicbrainz_url
),
ArtistCommand::MusicButler(url_command) => url_command_dispatch!(
ArtistCommand::MusicButler(url_command) => multi_url_command_dispatch!(
url_command,
music_hoard,
add_musicbutler_urls,
remove_musicbutler_urls,
set_musicbutler_urls,
clear_musicbutler_urls,
urls
clear_musicbutler_urls
),
ArtistCommand::Bandcamp(url_command) => url_command_dispatch!(
ArtistCommand::Bandcamp(url_command) => multi_url_command_dispatch!(
url_command,
music_hoard,
add_bandcamp_urls,
remove_bandcamp_urls,
set_bandcamp_urls,
clear_bandcamp_urls,
urls
clear_bandcamp_urls
),
ArtistCommand::Qobuz(url_command) => url_command_dispatch!(
ArtistCommand::Qobuz(url_command) => single_url_command_dispatch!(
url_command,
music_hoard,
add_qobuz_url,
remove_qobuz_url,
set_qobuz_url,
clear_qobuz_url,
url
clear_qobuz_url
),
}
}