async-serial 0.1.0

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

async-serial

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

Crates.io License

Quickstart

use async_serial::{open, SerialPort, SerialPortSettings}

let mut port = open("/dev/ttyUSB0")?;
port.reconfigure(&|settings| {
    settings.set_baud_rate(serial::Baud9600)?;
    Ok(())
})?;

// Async read — won't block the executor
let mut buf = [0u8; 256];
let n = port.read(&mut buf).await?;

How It Works

serial::SystemPort implements 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 the missing IoSafe and AsFd impls in a small newtype.

API

  • open(path) — opens a serial port and returns Async<SystemPort>
  • SystemPort::from_serial(port) — wraps an existing serial::SystemPort
  • Deref<Target = serial::SystemPort> — transparent access to all serial methods

License

MIT OR Apache-2.0