nt/
proto.rs

1use crate::nt::{callback::CallbackType, EntryData};
2use futures_channel::mpsc::Receiver;
3use nt_network::types::EntryValue;
4use std::collections::HashMap;
5
6pub mod client;
7pub mod server;
8#[cfg(feature = "websocket")]
9pub mod ws;
10
11pub trait NTBackend {
12    type State: State;
13}
14
15pub struct Client;
16impl NTBackend for Client {
17    type State = client::ClientState;
18}
19
20pub struct Server;
21impl NTBackend for Server {
22    type State = server::ServerState;
23}
24
25pub trait State {
26    fn entries(&self) -> &HashMap<u16, EntryData>;
27
28    fn entries_mut(&mut self) -> &mut HashMap<u16, EntryData>;
29
30    fn create_entry(&mut self, data: EntryData) -> crate::Result<Receiver<u16>>;
31
32    fn delete_entry(&mut self, id: u16);
33
34    fn update_entry(&mut self, id: u16, new_value: EntryValue);
35
36    fn update_entry_flags(&mut self, id: u16, flags: u8);
37
38    fn clear_entries(&mut self);
39
40    fn add_callback(
41        &mut self,
42        callback_type: CallbackType,
43        action: impl FnMut(&EntryData) + Send + 'static,
44    );
45}