misskey_api/entity.rs
1use crate::model::id::Id;
2
3/// Trait for entity types that has an ID.
4pub trait Entity {
5 /// Gets the ID.
6 fn id(&self) -> Id<Self>;
7}
8
9/// Trait for types that serves as a reference (i.e. ID) to `E`.
10pub trait EntityRef<E: Entity> {
11 /// Gets the reference to the entity.
12 fn entity_ref(&self) -> Id<E>;
13}
14
15impl<E: Entity> EntityRef<E> for &E {
16 fn entity_ref(&self) -> Id<E> {
17 self.id()
18 }
19}
20
21impl<E: Entity> EntityRef<E> for Id<E> {
22 fn entity_ref(&self) -> Id<E> {
23 *self
24 }
25}
26impl<E: Entity> EntityRef<E> for &Id<E> {
27 fn entity_ref(&self) -> Id<E> {
28 **self
29 }
30}