From ee0d4ee0d0baf0a9b612af7192381ed2d3d43e0a Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Sun, 2 Jun 2024 22:46:29 -0400 Subject: [PATCH] Added functions to create QueueItemType --- src/lib.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3a1d149..236ef57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,10 +21,10 @@ pub struct QueueItem< U: Debug + PartialEq + Clone + TrackGroup, // U: The Multi-Item Type. Needs to be tracked as multiple items L: Debug + PartialEq + Clone + Copy + Location // L: The Location Type. Optional but maybe useful > { - pub(crate) item: QueueItemType, - pub(crate) state: QueueState, - pub(crate) source: Option, - pub(crate) by_human: bool, + pub item: QueueItemType, + pub state: QueueState, + pub source: Option, + pub by_human: bool, } #[derive(Debug, Clone, PartialEq)] @@ -37,6 +37,20 @@ pub enum QueueItemType< Multi(U) } +impl< + T: Debug + Clone + PartialEq, // T: The Singular Item Type + U: Debug + PartialEq + Clone + TrackGroup, // U: The Multi-Item Type. Needs to be tracked as multiple items +> QueueItemType { + pub fn from_single(item: T) -> Self { + QueueItemType::Single(item) + } + + pub fn from_multi(item: U) -> Self { + QueueItemType::Multi(item) + } +} + + impl< T: Debug + Clone + PartialEq, U: Debug + PartialEq + Clone + TrackGroup, @@ -91,6 +105,15 @@ impl< ); } + pub fn new(loop_: bool, shuffle: Option>) -> Self { + Queue { + items: Vec::new(), + played: Vec::new(), + loop_, + shuffle + } + } + pub fn set_items(&mut self, tracks: Vec>) { let mut tracks = tracks; self.items.clear(); @@ -98,7 +121,8 @@ impl< } /// Inserts an item after the AddHere item - pub fn add_item(&mut self, item: QueueItemType, source: Option, by_human: bool) { + pub fn add_item(&mut self, item: T, source: Option, by_human: bool) { + let item = QueueItemType::from_single(item); let mut i: usize = 0; self.items = self @@ -128,7 +152,8 @@ impl< } /// Inserts an item after the currently playing item - pub fn add_item_next(&mut self, item: QueueItemType, source: Option) { + pub fn add_item_next(&mut self, item: T, source: Option) { + let item = QueueItemType::from_single(item); use QueueState::*; let empty = self.items.is_empty();