1#![deny(unsafe_code)]
4
5use std::borrow::Borrow;
6use std::cmp::Ordering;
7
8pub trait Equivalent<K: ?Sized> {
13 fn equivalent(&self, key: &K) -> bool;
15}
16
17impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
18where
19 Q: Eq,
20 K: Borrow<Q>,
21{
22 #[allow(clippy::inline_always)]
23 #[inline(always)]
24 fn equivalent(&self, key: &K) -> bool {
25 PartialEq::eq(self, key.borrow())
26 }
27}
28
29pub trait Comparable<K: ?Sized>: Equivalent<K> {
31 fn compare(&self, key: &K) -> Ordering;
33}
34
35impl<Q: ?Sized, K: ?Sized> Comparable<K> for Q
36where
37 Q: Ord,
38 K: Borrow<Q>,
39{
40 #[allow(clippy::inline_always)]
41 #[inline(always)]
42 fn compare(&self, key: &K) -> Ordering {
43 Ord::cmp(self, key.borrow())
44 }
45}