Crates.io | io-uring |
lib.rs | io-uring |
version | |
source | src |
created_at | 2019-05-30 11:14:08.732291 |
updated_at | 2024-11-25 13:19:37.51076 |
description | The low-level `io_uring` userspace interface for Rust |
homepage | https://github.com/tokio-rs/io-uring |
repository | https://github.com/tokio-rs/io-uring |
max_upload_size | |
id | 137876 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
The low-level io_uring
userspace interface for Rust.
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.
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.