Skip to main content

zaun_bot/voice/
queue.rs

1//! Queue control: remove, move, shuffle, clear and loop (WIT 0.2.0). A host that does not
2//! implement one yet answers `UNSUPPORTED` ([`HostError::is_unsupported`]).
3
4use super::{LoopMode, Voice, wit};
5use crate::types::HostError;
6
7impl Voice {
8    /// Removes the queued track at `index` (0 plays next); returns its title.
9    ///
10    /// # Errors
11    /// `NOT_FOUND` past the end of the queue; `UNSUPPORTED` on hosts without queue control.
12    pub fn remove(index: u32) -> Result<Option<String>, HostError> {
13        wit::remove(index)
14    }
15
16    /// Moves the queued track at `from` to `to` (both 0-based); the tracks between shift.
17    ///
18    /// # Errors
19    /// `NOT_FOUND` past the end of the queue; `UNSUPPORTED` on hosts without queue control.
20    pub fn move_track(from: u32, to: u32) -> Result<(), HostError> {
21        wit::move_(from, to)
22    }
23
24    /// Puts the queue in a random order; the current track keeps playing.
25    ///
26    /// # Errors
27    /// `UNSUPPORTED` on hosts without queue control.
28    pub fn shuffle() -> Result<(), HostError> {
29        wit::shuffle()
30    }
31
32    /// Empties the queue; unlike [`Voice::stop`], the current track keeps playing.
33    ///
34    /// # Errors
35    /// `UNSUPPORTED` on hosts without queue control.
36    pub fn clear_queue() -> Result<(), HostError> {
37        wit::clear_queue()
38    }
39
40    /// Sets what happens when a track ends: go on, repeat it, or requeue it at the end.
41    ///
42    /// # Errors
43    /// `UNSUPPORTED` on hosts without looping.
44    pub fn set_loop(mode: LoopMode) -> Result<(), HostError> {
45        wit::set_loop(mode)
46    }
47}