Krolyxon
Commit f3fb60a

rmptuisrclist.rs

39 lines · 723 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 let len = self.list.len();
18 if len != 0 && self.index < len - 1 {
19 self.index += 1;
20 }
21 }
22
23 /// Go to previous item in list
24 pub fn prev(&mut self) {
25 if self.index != 0 {
26 self.index -= 1;
27 }
28 }
29
30 pub fn reset_index(&mut self) {
31 self.index = 0;
32 }
33}
34
35impl<T> Default for ContentList<T> {
36 fn default() -> Self {
37 Self::new()
38 }
39}