#rustix #io-uring

rustix-uring

The low-level io_uring userspace interface for Rust

7 releases (breaking)

0.6.0 Apr 23, 2025
0.5.0 Apr 22, 2025
0.4.0 Mar 13, 2025
0.3.0 Mar 10, 2025
0.1.1 Mar 4, 2023

#128 in Asynchronous

Download history 35/week @ 2025-01-31 51/week @ 2025-02-07 75/week @ 2025-02-14 90/week @ 2025-02-21 61/week @ 2025-02-28 222/week @ 2025-03-07 144/week @ 2025-03-14 72/week @ 2025-03-21 117/week @ 2025-03-28 285/week @ 2025-04-04 152/week @ 2025-04-11 278/week @ 2025-04-18 147/week @ 2025-04-25 42/week @ 2025-05-02 71/week @ 2025-05-09 87/week @ 2025-05-16

409 downloads per month
Used in 3 crates

MIT/Apache

185KB
3.5K SLoC

A Linux io_uring API, using rustix

github actions crates license license docs.rs

This is a Linux io_uring userspace interface for Rust. It is higher-level than the userspace boundary API, but lower-level than an async runtime.

This library derived from the io_uring crate, and is modified to use rustix to perform the system calls.

Usage

To use the rustix-uring crate, first add this to your Cargo.toml:

[dependencies]
rustix-uring = "0.4"

Next we can start using the rustix-uring crate. The following is quick introduction using Read for file.

use rustix_uring::{opcode, types, IoUring};
use std::os::unix::io::AsRawFd;
use std::{fs, io};

fn main() -> io::Result<()> {
    let mut ring = IoUring::new(8)?;

    let fd = fs::File::open("README.md")?;
    let mut buf = vec![0; 1024];

    let read_e = opcode::Read::new(types::Fd(fd.as_raw_fd()), buf.as_mut_ptr(), buf.len() as _)
        .build()
        .user_data(0x42);

    // Note that the developer needs to ensure
    // that the entry pushed into submission queue is valid (e.g. fd, buffer).
    unsafe {
        ring.submission()
            .push(&read_e)
            .expect("submission queue is full");
    }

    ring.submit_and_wait(1)?;

    let cqe = ring.completion().next().expect("completion queue is empty");

    assert_eq!(cqe.user_data().u64_(), 0x42);
    let _bytes_read = cqe.result().expect("read error");

    Ok(())
}

Note that opcode Read is only available after kernel 5.6. If you use a kernel lower than 5.6, this example will fail.

Test and Benchmarks

You can run the test and benchmark of the library with the following commands.

$ cargo run --package io-uring-test
$ cargo bench --package io-uring-bench

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in io-uring by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.7–10MB
~123K SLoC