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
/*
    Appellation: appellation <module>
    Contrib: FL03 <jo3mccain@icloud.com>
    Description:
        An appellation is a more concise definition for the abstract naming schemes native to blockchain technologies,
        wrapping mission critical tags into a streamlined naming convention
*/
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Appellation<T = String> {
    pub id: T,
    pub key: T, // Key is meant for use with items like a CID from IPFS
    pub label: T,
}

impl<T> Appellation<T> {
    pub fn new(id: T, key: T, label: T) -> Self {
        Self { id, key, label }
    }
}

impl<T: Serialize> std::fmt::Debug for Appellation<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", serde_json::to_string_pretty(&self).unwrap())
    }
}

impl<T: Serialize> std::fmt::Display for Appellation<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", serde_json::to_string(&self).unwrap())
    }
}