async-serial 0.2.0

Lightweight async serial port adapter for async-io + serialport
Documentation
  • Coverage
  • 16.67%
    1 out of 6 items documented0 out of 3 items with examples
  • Size
  • Source code size: 29.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.02 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ZXY595/async-serial
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ZXY595

async-serial

Lightweight async serial port adapter — bridges [serialport] with [async-io].

Crates.io License

Quickstart

use async_serial::AsyncSerialPortBuilder;

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?;

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 missing IoSafe and AsFd impls
  • AsyncSerialPort — a type alias for Async<IoSafeAdapter<platform port>>
  • AsyncSerialPortBuilder — an extension trait that adds .open_async() to SerialPortBuilder

API

  • AsyncSerialPortBuilder::open_async() — opens a port via builder and wraps it for async IO
  • AsyncSerialPort — type alias: Async<IoSafeAdapter<TTYPort>> (unix) or Async<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