Type Definition tokio_uring::BufResult

source ·
pub type BufResult<T, B> = (Result<T>, B);
Expand description

A specialized Result type for io-uring operations with buffers.

This type is used as a return value for asynchronous io-uring methods that require passing ownership of a buffer to the runtime. When the operation completes, the buffer is returned whether or not the operation completed successfully.

Examples

use tokio_uring::fs::File;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    tokio_uring::start(async {
        // Open a file
        let file = File::open("hello.txt").await?;

        let buf = vec![0; 4096];
        // Read some data, the buffer is passed by ownership and
        // submitted to the kernel. When the operation completes,
        // we get the buffer back.
        let (res, buf) = file.read_at(buf, 0).await;
        let n = res?;

        // Display the contents
        println!("{:?}", &buf[..n]);

        Ok(())
    })
}