Crates.io | uring-fs |
lib.rs | uring-fs |
version | 1.4.0 |
source | src |
created_at | 2023-12-10 10:29:19.477632 |
updated_at | 2024-01-15 22:39:58.44165 |
description | Truly asynchronous file operations using io-uring. Supports any async runtime. Linux only. |
homepage | |
repository | https://github.com/Foxcirc/uring-fs |
max_upload_size | |
id | 1064132 |
size | 19,312 |
uring-fs
is a library that allows you to safely read files using async-await in rust
without needing a threadpool. It uses io_uring
.
IoUring
] documentation for more important infos and examples.let io = IoUring::new()?; // create a new io-uring context
let mut file: fs::File = io.open("src/foo.txt", Flags::RDONLY).await?;
// ^^^^ you could also use File::open or OpenOptions
let info = io.stat("src/foo.txt").await?;
// there is also read_all, which doesn't require querying the file size
// using stat, however this is a bit more efficient since we only allocate the data buffer once
let content = io.read(&file, info.size()).await?;
println!("we read {} bytes", content.len());
// btw you can also seek the file using io::Seek
file.seek(SeekFrom::Current(-10));
This library will spawn a reaper thread that waits for io-uring completions and notifies the apropriate future. Still, this is light weight in comparison to using a thread pool.
This crate doesn't have the same soundness problems as rio
, however it isn't as powerfull and doesn't provide a lot
of fine-grained controll.
If you want to use rio
, remember to, at some point, enable the no_metrics
feature!
Otherwise there will be a ~100ms initial allocation of space used to store the performance information.
Please also note that the code for this library is not tested as much as I'd like to and might contain some subtle undefined behaviour. This library is kept small and hackable so you can always verify and fork it yourself.
The whole code is contained inside lib.rs
.