The io_uring library for Rust
Find a file
2024-12-11 20:43:06 +01:00
.cargo update gitea index location to Uncollapse uppercase 2024-12-11 20:43:06 +01:00
.github/workflows impl ord,eq for bitflags 2024-10-17 22:23:20 +08:00
examples Fix fmt 2021-04-09 00:01:30 +08:00
io-uring-bench release 0.7.0 (#301) 2024-09-27 22:49:09 +08:00
io-uring-test Implement the ability for Send to act as SendTo (#309) 2024-11-25 10:32:58 +08:00
src add drive_cq to submitter 2024-12-11 17:34:52 +01:00
.gitignore release 0.6.2 2023-09-17 11:16:22 +08:00
build.rs release 0.7.0 (#301) 2024-09-27 22:49:09 +08:00
Cargo.lock update gitea index location to Uncollapse uppercase 2024-12-11 20:43:06 +01:00
Cargo.toml release 0.7.2 2024-11-25 21:12:12 +08:00
LICENSE-APACHE Add README and LICENSE-* 2019-10-19 16:52:52 +08:00
LICENSE-MIT Add README and LICENSE-* 2019-10-19 16:52:52 +08:00
README.md Fix README version 2023-04-09 13:12:53 +08:00

Linux IO Uring

github actions crates license license docs.rs

The low-level io_uring userspace interface for Rust.

Usage

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

[dependencies]
io-uring = "0.6"

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

use io_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(), 0x42);
    assert!(cqe.result() >= 0, "read error: {}", cqe.result());

    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.