Skip to content

Commit

Permalink
🔖🐛 Fix random ordering for playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmiddiii committed Sep 24, 2021
1 parent 1f6549b commit cfe2307
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion playlist/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 9 additions & 10 deletions playlist/src/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,34 @@
* along with Tubefeeder-extractor. If not, see <https://www.gnu.org/licenses/>.
*/

use std::hash::Hash;
use std::{collections::HashSet, sync::Mutex};
use std::sync::Mutex;

use tf_observer::{Observable, Observer, ObserverList};

pub struct Playlist<T> {
observers: ObserverList<PlaylistEvent<T>>,
playlist: HashSet<T>,
playlist: Vec<T>,
}

impl<T> Playlist<T>
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()))
}
}
Expand All @@ -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<T> Default for Playlist<T>
where
T: Hash + Eq + Clone,
T: Eq + Clone,
{
fn default() -> Self {
Self::new()
Expand Down

0 comments on commit cfe2307

Please sign in to comment.