use std::cmp::Ordering;
use std::marker::PhantomData;
pub trait WithLifetime<'a> {
type Out;
}
pub struct RefLifetime<T: ?Sized>(PhantomData<T>);
impl<'a, T: 'a + ?Sized> WithLifetime<'a> for RefLifetime<T> {
type Out = &'a T;
}
pub trait RadbKey {
type View: for<'a> WithLifetime<'a>;
fn from_bytes(data: &[u8]) -> <Self::View as WithLifetime>::Out;
fn as_bytes(&self) -> &[u8];
fn compare(data1: &[u8], data2: &[u8]) -> Ordering;
}
impl RadbKey for [u8] {
type View = RefLifetime<[u8]>;
fn from_bytes(data: &[u8]) -> <Self::View as WithLifetime>::Out {
data
}
fn as_bytes(&self) -> &[u8] {
self
}
fn compare(data1: &[u8], data2: &[u8]) -> Ordering {
data1.cmp(data2)
}
}