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
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(all(target_os = "linux", feature = "iouring")))]
let r = monoio::start::<monoio::LegacyDriver, _>(async {
// Open a file
let file = monoio::fs::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(())
});
#[cfg(all(target_os = "linux", feature = "iouring"))]
let r = Ok(());
r
}