Add Arist::display_list function

This commit is contained in:
Ethan Girouard 2024-07-23 22:57:24 -04:00
parent 8a474077da
commit c72d4aee18
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146

View File

@ -164,6 +164,26 @@ impl Artist {
Ok(my_songs) Ok(my_songs)
} }
/// Display a list of artists as a string.
///
/// For one artist, displays [artist1]. For two artists, displays [artist1] & [artist2].
/// For three or more artists, displays [artist1], [artist2], & [artist3].
pub fn display_list(artists: &Vec<Artist>) -> String {
let mut artist_list = String::new();
for (i, artist) in artists.iter().enumerate() {
if i == 0 {
artist_list.push_str(&artist.name);
} else if i == artists.len() - 1 {
artist_list.push_str(&format!(" & {}", artist.name));
} else {
artist_list.push_str(&format!(", {}", artist.name));
}
}
artist_list
}
} }
/// Model for an album /// Model for an album