rcommunity_core/markers/
types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Traits to mark struct as basic community types.

use crate::utils::typename;

pub trait UserType: ID + Serializable + Clone + Sync {}
pub trait ItemType: ID + Serializable + Clone + Sync {}
pub trait ReactionType: Serializable + Clone + Sync {}

pub trait ID {
    fn id(&self) -> &str;
}

pub trait Serializable {
    fn serialize(&self) -> String;
}
impl<T: ID> Serializable for T {
    fn serialize(&self) -> String {
        let typename = typename::<T>();
        format!("{typename}:{}", self.id())
    }
}