kithara_queue/queue/owner.rs
1use kithara_bufpool::HasPool;
2use kithara_events::TrackId;
3
4use super::{Queue, Transition};
5use crate::{QueueError, TrackSource};
6
7impl<S> Queue<S>
8where
9 S: HasPool<u8> + HasPool<f32> + Send + Sync + 'static,
10{
11 /// Append a track while this concrete queue remains owned by its caller.
12 ///
13 /// # Errors
14 ///
15 /// Returns [`QueueError::Play`] after the resident player is closed.
16 pub fn append<T: Into<TrackSource<S>>>(&self, source: T) -> Result<TrackId, QueueError> {
17 self.control.append(source)
18 }
19
20 /// Append a track with a caller-owned stable id.
21 ///
22 /// # Errors
23 ///
24 /// Returns [`QueueError::Play`] after the resident player is closed.
25 pub fn append_with_id<T: Into<TrackSource<S>>>(
26 &self,
27 id: TrackId,
28 source: T,
29 ) -> Result<TrackId, QueueError> {
30 self.control.append_with_id(id, source)
31 }
32
33 /// Insert a track after `after`, or at the head when it is absent.
34 ///
35 /// # Errors
36 ///
37 /// Returns [`QueueError`] when `after` is not present.
38 pub fn insert<T: Into<TrackSource<S>>>(
39 &self,
40 source: T,
41 after: Option<TrackId>,
42 ) -> Result<TrackId, QueueError> {
43 self.control.insert(source, after)
44 }
45
46 /// Insert a track with a caller-owned stable id.
47 ///
48 /// # Errors
49 ///
50 /// Returns [`QueueError`] when `after` is not present.
51 pub fn insert_with_id<T: Into<TrackSource<S>>>(
52 &self,
53 id: TrackId,
54 source: T,
55 after: Option<TrackId>,
56 ) -> Result<TrackId, QueueError> {
57 self.control.insert_with_id(id, source, after)
58 }
59
60 delegate::delegate! {
61 to self.control {
62 /// Advance to the next navigation-owned track.
63 ///
64 /// # Errors
65 ///
66 /// Returns a queue or player error when the successor cannot be selected.
67 pub fn next(&self, transition: Transition) -> Result<Option<TrackId>, QueueError>;
68
69 /// Return to the previous navigation-owned track.
70 ///
71 /// # Errors
72 ///
73 /// Returns a queue or player error when the predecessor cannot be selected.
74 pub fn previous(
75 &self,
76 transition: Transition,
77 ) -> Result<Option<TrackId>, QueueError>;
78 }
79 }
80}