1use crate::models::AliasEntry;
4
5#[derive(Debug, Clone)]
7pub struct EntryData {
8 entries: Vec<AliasEntry>,
10 visible_indices: Vec<usize>,
12}
13
14impl EntryData {
15 pub fn new(entries: Vec<AliasEntry>) -> Self {
17 Self {
18 entries,
19 visible_indices: Vec::new(),
20 }
21 }
22
23 pub fn entries(&self) -> &[AliasEntry] {
25 &self.entries
26 }
27
28 pub fn visible_indices(&self) -> &[usize] {
30 &self.visible_indices
31 }
32
33 pub(super) fn visible_indices_mut(&mut self) -> &mut Vec<usize> {
35 &mut self.visible_indices
36 }
37
38 pub fn get_visible_entry(
40 &self,
41 selected_index: usize,
42 ) -> Option<&AliasEntry> {
43 self.visible_indices.get(selected_index).and_then(|&idx| self.entries.get(idx))
44 }
45
46 pub fn visible_count(&self) -> usize {
48 self.visible_indices.len()
49 }
50
51 pub fn is_empty(&self) -> bool {
53 self.visible_indices.is_empty()
54 }
55
56 pub(super) fn sort_visible_indices<F>(
59 &mut self,
60 mut compare: F,
61 ) where
62 F: FnMut(&crate::models::AliasEntry, &crate::models::AliasEntry) -> std::cmp::Ordering,
63 {
64 self.visible_indices.sort_by(|&a, &b| compare(&self.entries[a], &self.entries[b]));
65 }
66}
67
68#[cfg(test)]
69#[path = "data_tests.rs"]
70mod data_tests;