practic_events_lib/
lib.rs

1#[macro_use]
2extern crate serde_derive;
3extern crate serde_json;
4
5use std::{convert::TryFrom, fmt};
6
7#[derive(Deserialize, fmt::Debug, Serialize)]
8pub struct TelegramNotification {
9    pub chat_id: i64,
10    pub message: String,
11}
12
13impl fmt::Display for TelegramNotification {
14    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15        write!(f, "({})", self.chat_id)
16    }
17}
18
19impl TryFrom<Vec<u8>> for TelegramNotification {
20    type Error = serde_json::Error;
21
22    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
23        serde_json::from_slice(&value)
24    }
25}
26
27impl TryFrom<TelegramNotification> for Vec<u8> {
28    type Error = serde_json::Error;
29
30    fn try_from(value: TelegramNotification) -> Result<Self, Self::Error> {
31        serde_json::to_vec(&value)
32    }
33}
34
35#[derive(Serialize, Deserialize)]
36pub struct Payslip {
37    pub sender_id: u32,
38    pub receiver_id: u32,
39    pub amount: u32,
40    pub currency: String,
41}