Skip to main content

NetworkTransport

Trait NetworkTransport 

Source
pub trait NetworkTransport<M> {
    // Required methods
    fn send(&mut self, msg: M) -> Result<(), TransportError>;
    fn recv(&mut self) -> Result<M, TransportError>;
    fn try_recv(&mut self) -> Result<Option<M>, TransportError>;
}
Expand description

A bidirectional message transport for link play.

Implementors are the wire half of a link connection: they move whole messages of the game’s protocol type M in and out, hiding framing, channels, threads, and sockets. The methods mirror std::sync::mpsc semantics: Self::recv blocks until a message or a disconnect arrives, Self::try_recv never blocks.

The engine defines this interface; each game implements it for its own wire message type (see the module docs).

Required Methods§

Source

fn send(&mut self, msg: M) -> Result<(), TransportError>

Send one message to the peer.

Source

fn recv(&mut self) -> Result<M, TransportError>

Block until a message arrives or the connection fails.

Source

fn try_recv(&mut self) -> Result<Option<M>, TransportError>

Non-blocking receive: Ok(None) when nothing is pending, Err(Disconnected) once the peer is gone.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<M> NetworkTransport<M> for ChannelTransport<M>

Available on non-bare-metal only.