pub trait KeyComparable {
type Key: PartialEq + ?Sized;
fn key(&self) -> &Self::Key;
}
macro_rules! impl_key_comparable {
($($t:ty)*) => ($(
impl KeyComparable for $t {
type Key = $t;
#[inline]
fn key(&self) -> &Self::Key { self }
}
)*)
}
impl_key_comparable! {
str bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64
}
impl KeyComparable for &str {
type Key = str;
fn key(&self) -> &Self::Key {
self
}
}
impl KeyComparable for String {
type Key = str;
fn key(&self) -> &Self::Key {
self
}
}