Krolyxon
Commit 9c30356

rmptuisrcqueue.rs

37 lines · 654 B · Rust

1use mpd::Song;
2
3#[derive(Debug)]
4pub struct Queue {
5 pub list: Vec<Song>,
6 pub index: usize,
7}
8
9impl Queue {
10 pub fn new() -> Self {
11 Queue {
12 list: Vec::new(),
13 index: 0,
14 }
15 }
16
17 // Go to next item in list
18 pub fn next(&mut self) {
19 let len = self.list.len();
20 if len != 0 {
21 if self.index < len - 1 {
22 self.index += 1;
23 }
24 }
25 }
26
27 /// Go to previous item in list
28 pub fn prev(&mut self) {
29 if self.index != 0 {
30 self.index -= 1;
31 }
32 }
33
34 pub fn reset_index(&mut self) {
35 self.index = 0;
36 }
37}