Expand description
Asynchronous File I/O module for Tokio
This module provides methods for asynchronous file I/O. On BSD-based operating systems, it uses mio-aio. On Linux, it could use libaio, but that isn’t implemented yet.
§Examples
use std::fs;
use std::io::Read;
use tempfile::TempDir;
use tokio::runtime;
use tokio_file::AioFileExt;
let contents = b"abcdef";
let mut rbuf = Vec::new();
let dir = TempDir::new().unwrap();
let path = dir.path().join("foo");
let file = fs::OpenOptions::new()
.create(true)
.write(true)
.open(&path)
.unwrap();
let rt = runtime::Builder::new_current_thread()
.enable_io()
.build()
.unwrap();
let r = rt.block_on(async {
file.write_at(contents, 0).unwrap().await
}).unwrap();
assert_eq!(r, contents.len());
drop(file);
let mut file = fs::File::open(&path).unwrap();
assert_eq!(file.read_to_end(&mut rbuf).unwrap(), contents.len());
assert_eq!(&contents[..], &rbuf[..]);
Traits§
- AioFile
Ext - Adds POSIX AIO-based asynchronous methods to files.
Type Aliases§
- ReadAt
- Return type of
AioFileExt::read_at
. ImplementsFuture
. - ReadvAt
- Return type of
AioFileExt::readv_at
. ImplementsFuture
. - SyncAll
- Return type of
AioFileExt::sync_all
. ImplementsFuture
. - WriteAt
- Return type of
AioFileExt::write_at
. ImplementsFuture
. - Writev
At - Return type of
AioFileExt::writev_at
. ImplementsFuture
.