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
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter, Result as FmtResult};
use utoipa::ToSchema;

// ? ---------------------------------------------------------------------------
// ? ChildrenEnum
// ? ---------------------------------------------------------------------------

/// This enumerator allow represents the children elements using their primary
/// keys (Ids option) or the true records (Record option).
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub enum ChildrenEnum<T, U> {
    Ids(Vec<U>),
    Records(Vec<T>),
}

impl<T, U> Display for ChildrenEnum<T, U>
where
    T: Display,
    U: Display,
{
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        match self {
            ChildrenEnum::Ids(_) => write!(f, "ids"),
            ChildrenEnum::Records(_) => write!(f, "records"),
        }
    }
}

// ? ---------------------------------------------------------------------------
// ? ParentEnum
// ? ---------------------------------------------------------------------------

/// This enumerator allow represents the parent elements using their primary
/// key (Id option) or the true record (Record option).
#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub enum ParentEnum<T, U> {
    Id(U),
    Record(T),
}

impl<T, U> Display for ParentEnum<T, U>
where
    T: Display,
    U: Display,
{
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        match self {
            ParentEnum::Id(_) => write!(f, "id"),
            ParentEnum::Record(_) => write!(f, "record"),
        }
    }
}