#[cfg(doc)]
use crate::VecProgress;
pub trait VecProgressEntry {
type Id: PartialEq;
type Progress: Clone + Default + Ord;
fn id(&self) -> &Self::Id;
fn progress(&self) -> &Self::Progress;
fn progress_mut(&mut self) -> &mut Self::Progress;
fn id_progress(&self) -> (&Self::Id, &Self::Progress) {
(self.id(), self.progress())
}
fn id_progress_owned(&self) -> (Self::Id, Self::Progress)
where Self::Id: Clone {
let (id, progress) = self.id_progress();
(id.clone(), progress.clone())
}
}
pub trait VecProgressEntryData: VecProgressEntry {
type Data;
fn data(&self) -> &Self::Data;
fn data_mut(&mut self) -> &mut Self::Data;
}
impl<ID, Progress> VecProgressEntry for (ID, Progress)
where
ID: PartialEq,
Progress: Clone + Default + Ord,
{
type Id = ID;
type Progress = Progress;
fn id(&self) -> &Self::Id {
&self.0
}
fn progress(&self) -> &Self::Progress {
&self.1
}
fn progress_mut(&mut self) -> &mut Self::Progress {
&mut self.1
}
}
#[cfg(test)]
mod tests {
use super::VecProgressEntry;
#[test]
fn test_tuple_entry() {
let mut entry = (3u64, 7u64);
assert_eq!(&3, entry.id());
assert_eq!(&7, entry.progress());
assert_eq!((&3, &7), entry.id_progress());
assert_eq!((3, 7), entry.id_progress_owned());
*entry.progress_mut() = 9;
assert_eq!((3, 9), entry);
}
}