sustenet_shared/
lib.rs

1use tokio::sync::mpsc::Sender;
2
3pub mod config;
4pub mod logging;
5pub mod network;
6pub mod packets;
7pub mod utils;
8
9pub mod security;
10
11pub mod macros;
12
13pub trait ServerPlugin: Send + Sync {
14    fn set_sender(&self, tx: Sender<Box<[u8]>>);
15
16    fn receive<'plug>(
17        &self,
18        tx: Sender<Box<[u8]>>,
19        command: u8,
20        reader: &'plug mut tokio::io::BufReader<tokio::net::tcp::ReadHalf<'_>>
21    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + 'plug>>;
22
23    /// Only used when debugging is enabled.
24    fn info(&self, message: &str);
25}
26
27pub trait ClientPlugin: Send + Sync {
28    fn set_sender(&self, tx: Sender<Box<[u8]>>);
29
30    fn receive_master<'plug>(
31        &self,
32        tx: Sender<Box<[u8]>>,
33        command: u8,
34        reader: &'plug mut tokio::io::BufReader<tokio::net::tcp::ReadHalf<'_>>
35    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + 'plug>>;
36
37    fn receive_cluster<'plug>(
38        &self,
39        tx: Sender<Box<[u8]>>,
40        command: u8,
41        reader: &'plug mut tokio::io::BufReader<tokio::net::tcp::ReadHalf<'_>>
42    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = ()> + Send + 'plug>>;
43
44    /// Only used when debugging is enabled.
45    fn info(&self, message: &str);
46}
47
48// TODO: Use a Result instead.
49// #[derive(Debug)]
50// pub enum PluginError {
51//     Other {
52//         msg: String,
53//     },
54// }