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§
Sourcefn send(&mut self, msg: M) -> Result<(), TransportError>
fn send(&mut self, msg: M) -> Result<(), TransportError>
Send one message to the peer.
Sourcefn recv(&mut self) -> Result<M, TransportError>
fn recv(&mut self) -> Result<M, TransportError>
Block until a message arrives or the connection fails.
Sourcefn try_recv(&mut self) -> Result<Option<M>, TransportError>
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".