moving to using a filter function for getting the item

This commit is contained in:
Chris Cochrun 2024-10-09 14:47:07 -05:00
parent f3c3e98e16
commit 0bfa2c6089
6 changed files with 16 additions and 18 deletions

View file

@ -36,8 +36,11 @@ impl<T> Model<T> {
Ok(())
}
pub fn get_item(&self, index: i32) -> Option<&T> {
self.items.get(index as usize)
pub fn get_item<P>(&self, f: P) -> Option<&T>
where
P: FnMut(&&T) -> bool,
{
self.items.iter().filter(f).next()
}
pub fn insert_item(&mut self, item: T, index: i32) -> Result<()> {