use crate::models::AliasEntry;
#[derive(Debug, Clone)]
pub struct EntryData {
entries: Vec<AliasEntry>,
visible_indices: Vec<usize>,
}
impl EntryData {
pub fn new(entries: Vec<AliasEntry>) -> Self {
Self {
entries,
visible_indices: Vec::new(),
}
}
pub fn entries(&self) -> &[AliasEntry] {
&self.entries
}
pub fn visible_indices(&self) -> &[usize] {
&self.visible_indices
}
pub(super) fn visible_indices_mut(&mut self) -> &mut Vec<usize> {
&mut self.visible_indices
}
pub fn get_visible_entry(
&self,
selected_index: usize,
) -> Option<&AliasEntry> {
self.visible_indices.get(selected_index).and_then(|&idx| self.entries.get(idx))
}
pub fn visible_count(&self) -> usize {
self.visible_indices.len()
}
pub fn is_empty(&self) -> bool {
self.visible_indices.is_empty()
}
pub(super) fn sort_visible_indices<F>(
&mut self,
mut compare: F,
) where
F: FnMut(&crate::models::AliasEntry, &crate::models::AliasEntry) -> std::cmp::Ordering,
{
self.visible_indices.sort_by(|&a, &b| compare(&self.entries[a], &self.entries[b]));
}
}
#[cfg(test)]
#[path = "data_tests.rs"]
mod data_tests;