Skip to main content

Transport

Trait Transport 

Source
pub trait Transport: Send {
    // Required methods
    fn send(&mut self, data: &[u8]) -> Result<()>;
    fn recv(&mut self, buf: &mut [u8]) -> Result<usize>;
    fn close(&mut self) -> Result<()>;
}
Expand description

A connected, reliable, ordered, bidirectional byte transport.

Implementations deliver complete protocol messages: one send is observed as exactly one recv payload. Callers provide a buffer to recv; if the buffer is smaller than the pending message, the transport fills what it can. Specific transports document how they handle undersized buffers (the built-in inproc/mock transports deliver a prefix and drop the remainder).

Required Methods§

Source

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

Enqueue data for delivery to the peer.

Source

fn recv(&mut self, buf: &mut [u8]) -> Result<usize>

Receive the next pending message into buf, returning the number of bytes written.

Source

fn close(&mut self) -> Result<()>

Tear down the transport. After this, send and recv return Error::Closed.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§