aboutsummaryrefslogtreecommitdiff
path: root/src/routes/messages.rs
blob: 7b7a70bdf976f8eafcd4d3584e03d61a20bb5d1e (plain) (blame)
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
use std::{collections::HashMap, marker::Sized};

#[derive(Serialize)]
pub struct OutgoingMsg<T> {
    pub result_type: String,
    pub content: T,
}

pub trait Message {
    fn name(&self) -> String;
    fn as_outgoing(self) -> OutgoingMsg<Self>
    where
        Self: Sized,
    {
        OutgoingMsg {
            result_type: self.name(),
            content: self,
        }
    }
}

#[derive(Serialize)]
pub struct Callback {
    pub path: Vec<String>,
    pub request: String,
    pub content: HashMap<String, String>,
}

impl Message for Callback {
    fn name(&self) -> String {
        String::from("CALLBACK")
    }
}

#[derive(Serialize)]
pub struct NotUnderstood {
    pub path: Vec<String>,
}

impl Message for NotUnderstood {
    fn name(&self) -> String {
        String::from("NOT_UNDERSTOOD")
    }
}