Lightweight async serial port adapter — bridges [serialport] with [async-io].
use async_serial::AsyncSerialPortBuilder as _;
let mut port = serialport::new("/dev/ttyUSB0", 9_600)
.open_async()?;
// Async read — won't block the executor
let mut buf = [0u8; 256];
let n = port.read(&mut buf).await?;serialport::TTYPort / serialport::COMPort implement Read + Write but those are blocking calls. async-io provides an Async<T> wrapper that makes any IoSafe + AsFd type non-blocking via the reactor.
This crate provides:
IoSafeAdapter<T>— a newtype that supplies the missingIoSafeandAsFdimplsAsyncSerialPort— a type alias forAsync<IoSafeAdapter<platform port>>AsyncSerialPortBuilder— an extension trait that adds.open_async()toSerialPortBuilder
| Platform | Backend type |
|---|---|
| Unix | TTYPort |
| Windows | COMPort |
MIT OR Apache-2.0