Krolyxon
Commit 9e2b51c

rmptuisrclist.rs

36 lines · 733 B · Rust

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