diff --git a/playlist/Cargo.toml b/playlist/Cargo.toml index bac1cab..a848856 100644 --- a/playlist/Cargo.toml +++ b/playlist/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playlist" -version = "0.1.0" +version = "0.1.1" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/playlist/src/playlist.rs b/playlist/src/playlist.rs index 82573d7..1ed95f3 100644 --- a/playlist/src/playlist.rs +++ b/playlist/src/playlist.rs @@ -17,35 +17,34 @@ * along with Tubefeeder-extractor. If not, see . */ -use std::hash::Hash; -use std::{collections::HashSet, sync::Mutex}; +use std::sync::Mutex; use tf_observer::{Observable, Observer, ObserverList}; pub struct Playlist { observers: ObserverList>, - playlist: HashSet, + playlist: Vec, } impl Playlist where - T: Hash + Eq + Clone, + T: Eq + Clone, { pub fn new() -> Self { Self { observers: ObserverList::new(), - playlist: HashSet::new(), + playlist: Vec::new(), } } pub fn toggle(&mut self, item: &T) { - if let Some(_i) = self.playlist.get(item) { + if let Some(_i) = self.playlist.iter().find(|&i| i == item) { log::debug!("Removing item from playlist"); - self.playlist.remove(item); + self.playlist.retain(|i| i != item); self.observers.notify(PlaylistEvent::Remove(item.clone())) } else { log::debug!("Adding item to playlist"); - self.playlist.insert(item.clone()); + self.playlist.push(item.clone()); self.observers.notify(PlaylistEvent::Add(item.clone())) } } @@ -59,13 +58,13 @@ where } pub fn get(&self, item: &T) -> Option<&T> { - self.playlist.get(item) + self.playlist.iter().find(|&i| i == item) } } impl Default for Playlist where - T: Hash + Eq + Clone, + T: Eq + Clone, { fn default() -> Self { Self::new()