Network

Trait Network 

Source
pub trait Network {
    type Addr: Ord;

    // Required methods
    fn start(&mut self) -> Result<(), NetworkError>;
    fn stop(&mut self) -> Result<(), NetworkError>;
    fn local_addr(&self) -> Self::Addr;
    fn advertise(&mut self) -> Result<(), NetworkError>;
    fn recv(&mut self) -> Result<Option<(Self::Addr, Box<[u8]>)>, NetworkError>;
    fn send(
        &mut self,
        addr: Self::Addr,
        data: &[u8],
    ) -> Result<(), NetworkError>;
    fn send_status(
        &mut self,
        addr: Self::Addr,
    ) -> Result<SendStatus, NetworkError>;
}

Required Associated Types§

Source

type Addr: Ord

The type representing the network address. Must be unique.

For emulator, it is IP+port. For the physical device, it is MAC address.

Required Methods§

Source

fn start(&mut self) -> Result<(), NetworkError>

Source

fn stop(&mut self) -> Result<(), NetworkError>

Source

fn local_addr(&self) -> Self::Addr

Network address of the current device as visible to the other peers.

Used to sort all the peers, including the local one, in the same order on all devices.

Source

fn advertise(&mut self) -> Result<(), NetworkError>

Source

fn recv(&mut self) -> Result<Option<(Self::Addr, Box<[u8]>)>, NetworkError>

Get a pending message, if any. Non-blocking.

Source

fn send(&mut self, addr: Self::Addr, data: &[u8]) -> Result<(), NetworkError>

Send a raw message to the given device. Non-blocking.

Source

fn send_status(&mut self, addr: Self::Addr) -> Result<SendStatus, NetworkError>

Send a raw message to the given device. Non-blocking.

Implementors§