Skip to main content

ByteStream

Trait ByteStream 

Source
pub trait ByteStream {
    // Required methods
    async fn read(&mut self, buf: &mut [u8], timeout: Duration) -> Result<usize>;
    async fn write(&mut self, data: &[u8]) -> Result<()>;
    async fn purge(&mut self) -> Result<()>;
}
Expand description

A byte stream: serial ports, USB-serial chips, Bluetooth classic RFCOMM, or a BLE GATT link that behaves like a serial line.

Required Methods§

Source

async fn read(&mut self, buf: &mut [u8], timeout: Duration) -> Result<usize>

Reads at least one byte into buf and returns how many bytes were read.

§Errors

Error::Timeout if no byte arrives within timeout, or a transport error.

Source

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

Writes all of data.

§Errors

A transport error if the write fails.

Source

async fn purge(&mut self) -> Result<()>

Discards any received data that has not been read yet.

§Errors

A transport error if the backend cannot purge.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§