1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/*
Appellation: appellation <module>
Contrib: FL03 <jo3mccain@icloud.com>
Description:
An appellation is defined to be a name or title given to a person or thing.
For our purposes, an appellation describes a novel naming schematic used to accelaerate the process of identifying persistent objects hosted on a multi-layered peer-to-peer network.
An appellation is composed of three parts: a classifier, an identifier, and a name.
The class is a classifier that describes the type of object being identified.
The id is a unique identifier that distinguishes the object from all other objects of the same class.
The name is a human-readable string that is used to identify the object in a human-readable context.
*/
//! # appellation
use crate::prelude::{Classifier, Identifier};
pub trait Appellation<Cls>
where
Cls: Classifier,
{
type Id: Identifier;
fn class(&self) -> &Cls;
fn id(&self) -> &Self::Id;
fn name(&self) -> String;
fn slug(&self) -> String {
self.name().to_lowercase().replace(" ", "-")
}
}
pub trait FromAppellation<Cls, Id>
where
Cls: Classifier,
Id: Identifier,
{
fn from_appellation(appellation: impl Appellation<Cls, Id = Id>) -> Self;
}
pub trait TryFromAppellation<Cls, Id>
where
Cls: Classifier,
Id: Identifier,
Self: Sized,
{
type Error;
fn try_from_appellation(
appellation: impl Appellation<Cls, Id = Id>,
) -> Result<Self, Self::Error>;
}
pub trait IntoAppellation<Cls, Id>
where
Cls: Classifier,
Id: Identifier,
{
fn into_appellation(self) -> dyn Appellation<Cls, Id = Id>;
}
impl<Cls, Id, T> Appellation<Cls> for (Cls, Id, T)
where
Cls: Classifier,
Id: Identifier,
T: ToString,
{
type Id = Id;
fn class(&self) -> &Cls {
&self.0
}
fn id(&self) -> &Id {
&self.1
}
fn name(&self) -> String {
self.2.to_string()
}
}