use super::*;
use std::cmp::Ord;
use std::hash::Hash;
pub trait Identifier: Copy + Eq + Hash + Ord + Send + Sync + 'static {}
impl<T: Copy + Eq + Hash + Ord + Send + Sync + 'static> Identifier for T {}
pub trait Identity {
type ID: Identifier;
fn id(&self) -> Self::ID;
}
#[doc = include_str!("../doc/entity.md")]
pub trait Entity: Identity + Clone + 'static {
#[doc = include_str!("../doc/entity/belongs-to-key.md")]
fn belongs_to_key<T: Entity>(&self) -> T::ID
where
Self: BelongsToForeignKey<T>,
{
<Self as BelongsToForeignKey<T>>::key(self)
}
#[doc = include_str!("../doc/entity/belongs-to.md")]
fn belongs_to<T: Entity>(&self, entity: &T) -> bool
where
Self: BelongsToForeignKey<T>,
{
self.belongs_to_key::<T>() == entity.id()
}
#[doc = include_str!("../doc/entity/has-many-key.md")]
fn has_many_key<T: Entity>(&self, entity: &T) -> Self::ID
where
Self: HasManyForeignKey<T>,
{
<Self as HasManyForeignKey<T>>::key(entity)
}
#[doc = include_str!("../doc/entity/is-owner-of.md")]
fn is_owner_of<T: Entity>(&self, entity: &T) -> bool
where
Self: HasManyForeignKey<T>,
{
self.has_many_key(entity) == self.id()
}
}