rf_distributed/network/
asynchronous.rs

1use crate::network::{NetworkResult, NetworkUpdate};
2use async_trait::async_trait;
3
4/// This trait represent a network that will be used to send and receive messages
5#[async_trait]
6pub trait Network {
7    /// Send a message to the network
8    ///
9    /// # Arguments
10    ///
11    /// * `source` - The source of the message
12    /// * `msg` - The message to send
13    ///
14    /// # Returns
15    ///
16    /// * `Ok(())` - If the message has been sent
17    /// * `Err(e)` - If an error occurred
18    async fn send(&mut self, source: i32, msg: String) -> NetworkResult<()>;
19    /// Receive a message from the network
20    ///
21    /// # Returns
22    ///
23    /// * `Ok(NetworkUpdate)` - If a message has been received
24    /// * `Err(e)` - If an error occurred
25    async fn receive(&mut self) -> NetworkResult<NetworkUpdate>;
26}