added a find function to model
This commit is contained in:
parent
125289ace1
commit
3e1e46ce2b
5 changed files with 16 additions and 11 deletions
|
@ -36,11 +36,16 @@ impl<T> Model<T> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_item<P>(&self, f: P) -> Option<&T>
|
||||
pub fn get_item(&self, index: i32) -> Option<&T>
|
||||
{
|
||||
self.items.get(index as usize)
|
||||
}
|
||||
|
||||
pub fn find<P>(&self, f: P) -> Option<&T>
|
||||
where
|
||||
P: FnMut(&&T) -> bool,
|
||||
{
|
||||
self.items.iter().filter(f).next()
|
||||
self.items.iter().find(f)
|
||||
}
|
||||
|
||||
pub fn insert_item(&mut self, item: T, index: i32) -> Result<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue