xmpd/src/manifest/playlist.rs

57 lines
1.2 KiB
Rust

use egui::ahash::HashMap;
use serde::{Deserialize, Serialize};
use super::song::Song;
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct Playlist {
songs: HashMap<String, Song>
}
impl Playlist {
pub fn new() -> Self {
Self { ..Default::default() }
}
pub fn add_song(&mut self, name: String, song: Song) -> Option<Song> {
self.songs.insert(name, song)
}
pub fn remove_song(&mut self, name: &String) -> Option<Song> {
self.songs.remove(name)
}
pub fn get_song(&self, name: &String) -> Option<&Song> {
self.songs.get(name)
}
pub fn get_songs(&self) -> &HashMap<String, Song> {
&self.songs
}
pub fn get_songs_mut(&mut self) -> &mut HashMap<String, Song> {
&mut self.songs
}
pub fn get_song_mut(&mut self, name: &String) -> Option<&mut Song> {
self.songs.get_mut(name)
}
pub fn len(&self) -> usize {
self.songs.len()
}
}
impl IntoIterator for Playlist {
type Item = (String, Song);
type IntoIter = std::collections::hash_map::IntoIter<String, Song>;
fn into_iter(self) -> Self::IntoIter {
self.songs.into_iter()
}
}