async-serial
Lightweight async serial port adapter — bridges [serialport] with [async-io].
Quickstart
use AsyncSerialPortBuilder;
let mut port = new
.open_async?;
// Async read — won't block the executor
let mut buf = ;
let n = port.read.await?;
How It Works
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
API
AsyncSerialPortBuilder::open_async()— opens a port via builder and wraps it for async IOAsyncSerialPort— type alias:Async<IoSafeAdapter<TTYPort>>(unix) orAsync<IoSafeAdapter<COMPort>>(windows)IoSafeAdapter<T>—Deref<Target = T>, all serial methods accessible transparently- Re-exports:
Async,SerialPortBuilder,new,Error,Result
Platform Support
| Platform | Backend type |
|---|---|
| Unix | TTYPort |
| Windows | COMPort |
License
MIT OR Apache-2.0