Add Arist::display_list function
This commit is contained in:
parent
8a474077da
commit
c72d4aee18
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user