Skip to main content

PhysicalTransport

Trait PhysicalTransport 

Source
pub trait PhysicalTransport {
    // Required methods
    fn send(&mut self, data: &[u8]) -> Result<()>;
    fn receive(&mut self, buf: &mut [u8]) -> Result<usize>;

    // Provided method
    fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()> { ... }
}
Expand description

A bidirectional byte channel abstracting the physical medium.

Framing sub-layers (HDLC, wrapper) are built on top of this trait, so they are independent of whether the underlying medium is a serial line, a TCP connection or a UDP socket.

Required Methods§

Source

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

Sends all of data over the medium.

Source

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

Receives bytes into buf, returning the number of bytes read. A return value of 0 indicates end of stream.

Provided Methods§

Source

fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()>

Sets the maximum time a subsequent receive call may block before returning an io::ErrorKind::TimedOut (or io::ErrorKind::WouldBlock) error. None waits indefinitely (the default behaviour, and what every receive implementation must do when this method is never called).

Used by crate::transport::hdlc::HdlcLayer to enforce the IEC 62056-46 inter-octet and inactivity timeouts. The default implementation is a no-op that returns Ok(()): a transport that ignores this request (i.e. keeps blocking indefinitely) makes those timeouts inactive but otherwise behaves exactly as before this method existed — mirrors std::net::TcpStream::set_read_timeout, which most network transports can delegate to directly.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§