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
/*
    Appellation: catalyst <module>
    Creator: FL03 <jo3mccain@icloud.com>
    Description: ... Summary ...
*/
use crate::{messages::Message, Direction};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Catalyst<S: Clone = String, T: Clone = String> {
    pub data: Vec<Direction<Message<S>, Message<T>>>,
}

impl<S: Clone, T: Clone> Catalyst<S, T> {
    pub fn new() -> Self {
        let data = Vec::new();

        Self { data }
    }
}

impl<S: Clone, T: Clone> Default for Catalyst<S, T> {
    fn default() -> Self {
        Self::new()
    }
}

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

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default() {
        let a = Catalyst::<String, String>::default();
        let b = a.clone();
        assert_eq!(&a, &b)
    }
}