| Crates.io | rustix-uring |
| lib.rs | rustix-uring |
| version | 0.6.0 |
| created_at | 2023-03-03 18:54:39.041895+00 |
| updated_at | 2025-04-23 20:34:52.937106+00 |
| description | The low-level `io_uring` userspace interface for Rust |
| homepage | https://github.com/jordanisaacs/rustix-uring |
| repository | https://github.com/jordanisaacs/rustix-uring |
| max_upload_size | |
| id | 799987 |
| size | 242,898 |
io_uring API, using rustixThis 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.
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.
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
This project is licensed under either of
at your option.
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.