use std::borrow::Cow;
pub trait KeyType {
type Description: KeyDescription + ?Sized;
type Payload: KeyPayload + ?Sized;
fn name() -> &'static str;
}
pub trait KeyDescription {
fn description(&self) -> Cow<str>;
}
impl KeyDescription for str {
fn description(&self) -> Cow<str> {
Cow::Borrowed(self)
}
}
impl KeyDescription for String {
fn description(&self) -> Cow<str> {
Cow::Borrowed(self)
}
}
pub trait KeyPayload {
fn payload(&self) -> Cow<[u8]>;
}
impl KeyPayload for () {
fn payload(&self) -> Cow<[u8]> {
Cow::Borrowed(&[])
}
}
impl KeyPayload for str {
fn payload(&self) -> Cow<[u8]> {
Cow::Borrowed(self.as_bytes())
}
}
impl KeyPayload for String {
fn payload(&self) -> Cow<[u8]> {
Cow::Borrowed(self.as_bytes())
}
}
impl KeyPayload for [u8] {
fn payload(&self) -> Cow<[u8]> {
Cow::Borrowed(self)
}
}
impl KeyPayload for Vec<u8> {
fn payload(&self) -> Cow<[u8]> {
Cow::Borrowed(self)
}
}
pub trait RestrictableKeyType: KeyType {
type Restriction: KeyRestriction + ?Sized;
}
pub trait KeyRestriction {
fn restriction(&self) -> Cow<str>;
}
impl KeyRestriction for str {
fn restriction(&self) -> Cow<str> {
Cow::Borrowed(self)
}
}
impl KeyRestriction for String {
fn restriction(&self) -> Cow<str> {
Cow::Borrowed(self)
}
}