use std::str::FromStr;
use crate::spicedb;
pub trait Entity {
type Relations: Relation;
type Id: FromStr + Into<String>;
fn object_type() -> &'static str;
}
pub trait Relation {
fn name(self) -> &'static str;
}
pub trait Resource: Entity {
type Permissions: Permission;
}
pub trait Permission {
fn name(self) -> &'static str;
}
impl<S> Permission for S
where
S: Into<&'static str>,
{
fn name(self) -> &'static str {
self.into()
}
}
impl<S> Relation for S
where
S: Into<&'static str>,
{
fn name(self) -> &'static str {
self.into()
}
}
pub trait Caveat {
type ContextStruct: Into<prost_types::Struct>;
fn name() -> &'static str;
}
pub trait Actor {
fn to_subject(&self) -> spicedb::SubjectReference;
}
pub struct NoCaveat;
impl Caveat for NoCaveat {
type ContextStruct = prost_types::Struct;
fn name() -> &'static str {
unreachable!()
}
}
pub struct NoRelations;
impl Relation for NoRelations {
fn name(self) -> &'static str {
unreachable!()
}
}
impl FromStr for NoRelations {
type Err = ();
fn from_str(_: &str) -> Result<Self, Self::Err> {
unreachable!()
}
}
pub struct WildCardId;
impl FromStr for WildCardId {
type Err = ();
fn from_str(_: &str) -> Result<Self, Self::Err> {
unreachable!()
}
}
impl From<WildCardId> for String {
fn from(_: WildCardId) -> Self {
"*".into()
}
}