use super::wrappers::CmpByKey;
pub struct KeyCmpContext<KF> {
key_func: KF
}
impl<KF> KeyCmpContext<KF> {
pub fn new<T, K>(key_func: KF) -> KeyCmpContext<KF>
where KF: Fn(&T) -> K
{
KeyCmpContext {key_func}
}
pub fn wrap<T>(&self, value: T) -> CmpByKey<KF, T> where
{
CmpByKey::new(value, &self.key_func)
}
}
#[cfg(test)]
mod test {
#[test]
fn context_new_accept_reference() {
use super::KeyCmpContext;
let _by_length = KeyCmpContext::new(&|v: &Vec<i32>| v.len());
}
}