lio 0.3.0

A platform-independent async I/O library with native support for io_uring (Linux), IOCP (Windows), and kqueue (macOS)
Documentation

Lio - Platform-Independent Async I/O Library

Lio is a high-performance, platform-independent async I/O library that uses the most efficient IO for each platform.

Features

  • Zero-copy operations where possible.
  • Automatic fallback to blocking operations when async isn't supported.
  • Manual control with high level async API.

Note: This is a quite low-level library. This library creates os resources (fd's) which it doesn't cleanup automatically.

Platform support

Platform I/O Mechanism Status
Linux io_uring Yes
Windows IOCP Not supported (planned)
macOS kqueue Yes
Other Unix poll/epoll/event ports Yes

Quick Start

# #![cfg(feature = "high")]
use std::os::fd::RawFd;

fn handle_result(result: std::io::Result<i32>, buf: Vec<u8>) {
  println!("result: {result:?}, buf: {buf:?}");
}

async fn example() -> std::io::Result<()> {
    let fd: RawFd = 1; // stdout
    let data = b"Hello, World!\n".to_vec();

    // Async API (on "high" feature flag).
    let (result, buf) = lio::write(fd, data.clone(), 0).await;
    handle_result(result, buf);

    // Channel API (on "high" feature flag).
    let receiver: oneshot::Receiver<(std::io::Result<i32>, Vec<u8>)> = lio::write(fd, data.clone(), 0).get_receiver();
    let (result, buf) = receiver.recv().unwrap();
    handle_result(result, buf);

    // Callback API.
    lio::write(fd, data.clone(), 0).when_done(|(result, buf)| {
      handle_result(result, buf);
    });

    Ok(())
}

Note: Only one of these API's can be used for one operation.

Safety and Threading

  • The library handles thread management for background I/O processing
  • Operations can be safely used across different threads

Error Handling

All operations return [std::io::Result] or [BufResult] for operations that return buffers. Errors are automatically converted from platform-specific error codes to Rust's standard I/O error types.