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
#[macro_use]
extern crate serde_derive;
extern crate serde_json;

use std::{convert::TryFrom, fmt};

#[derive(Deserialize, fmt::Debug, Serialize)]
pub struct TelegramNotification {
    pub chat_id: i64,
    pub message: String,
}

impl fmt::Display for TelegramNotification {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "({})", self.chat_id)
    }
}

impl TryFrom<Vec<u8>> for TelegramNotification {
    type Error = serde_json::Error;

    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
        serde_json::from_slice(&value)
    }
}

impl TryFrom<TelegramNotification> for Vec<u8> {
    type Error = serde_json::Error;

    fn try_from(value: TelegramNotification) -> Result<Self, Self::Error> {
        serde_json::to_vec(&value)
    }
}

#[derive(Serialize, Deserialize)]
pub struct Payslip {
    pub sender_id: u32,
    pub receiver_id: u32,
    pub amount: u32,
    pub currency: String,
}