diff --git a/src/models.rs b/src/models.rs index 349ed74..caa52ed 100644 --- a/src/models.rs +++ b/src/models.rs @@ -164,6 +164,26 @@ impl Artist { 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) -> 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