Crate uring_fs

source ·
Expand description

Features

  • Truly asynchronous and safe file operations using io-uring.
  • Usable with any async runtime.
  • Supports: open, stat, read, write.
  • Depends on io_uring and libc. So it doesn’t run on any operating systems that these don’t support.

See IoUring documentation for more important infos and examples.

Example

let io = IoUring::new()?; // create a new io-uring context
let mut file: fs::File = io.open("src/file.txt", Flags::RDONLY).await?;
//            ^^^^ you could also use File::open or OpenOptions
let info = io.stat("src/file.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));

Notes

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.

Structs

  • Like OpenOptions. Use libc or the associated constants.
  • An io-uring subsystem. Can be shared between threads safely.
  • Result of a stat operation. Information about a file.