moving to using a filter function for getting the item
This commit is contained in:
parent
f3c3e98e16
commit
0bfa2c6089
6 changed files with 16 additions and 18 deletions
|
@ -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<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue