Krolyxon
Commit 9ff7ca4

rmptuisrclist.rs

30 lines · 581 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 Self {
10 list: Vec::new(),
11 index: 0,
12 }
13 }
14
15 pub fn next(&mut self) {
16 if let Some(last) = self.list.len().checked_sub(1) {
17 self.index = self.index.saturating_add(1).min(last);
18 }
19 }
20
21 pub fn prev(&mut self) {
22 self.index = self.index.saturating_sub(1);
23 }
24}
25
26impl<T> Default for ContentList<T> {
27 fn default() -> Self {
28 Self::new()
29 }
30}