use std::borrow::Borrow;
use std::cmp::Ordering;
pub trait Equivalent<K: ?Sized> {
fn equivalent(&self, key: &K) -> bool;
}
impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
where
Q: Eq,
K: Borrow<Q>,
{
#[inline]
fn equivalent(&self, key: &K) -> bool {
PartialEq::eq(self, key.borrow())
}
}
pub trait Comparable<K: ?Sized>: Equivalent<K> {
fn compare(&self, key: &K) -> Ordering;
}
impl<Q: ?Sized, K: ?Sized> Comparable<K> for Q
where
Q: Ord,
K: Borrow<Q>,
{
#[inline]
fn compare(&self, key: &K) -> Ordering {
Ord::cmp(self, key.borrow())
}
}