pub fn start<D, F>(future: F) -> F::Output
Expand description
Start a monoio runtime.
§Examples
Basic usage
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
}