I want a sorted vector of (Key, Type), which is sorted only by Key.
I came up with the code below:
struct SortedVec<K, T> {
data: Vec<(K, T)>
}
impl<K: Ord, T> SortedVec<K, T> {
fn new() -> SortedVec<K, T> {
SortedVec { data: Vec::new() }
}
fn add(&mut self, k: K, t: T) {
self.data.push((k, t));
self.data.sort_by(|a, b| a.0.cmp(&b.0));
}
fn find<P>(&self, predicate: P) -> Option<&(K, T)> where P: FnMut(&(K, T)) -> bool {
self.data.iter().find(predicate)
}
}
But this doesn't compile with the following errors:
anon>:16:30: 16:45 error: the trait `for<'r> core::ops::FnMut<(&'r &(K, T),)>` is not implemented for the type `P` [E0277]
anon>:16 self.data.iter().find(predicate)
^~~~~~~~~~~~~~~
<anon>:16:30: 16:45 error: the trait `for<'r> core::ops::FnOnce<(&'r &(K, T),)>` is not implemented for the type `P` [E0277]
<anon>:16 self.data.iter().find(predicate)
^~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
playpen: application terminated with error code 101
I can't find anything wrong with the type 'P'.
How can I fix it?