tokio_file/lib.rs
1// vim: tw=80
2//! Asynchronous File I/O module for Tokio
3//!
4//! This module provides methods for asynchronous file I/O. On BSD-based
5//! operating systems, it uses mio-aio. On Linux, it could use libaio, but that
6//! isn't implemented yet.
7//!
8//! # Examples
9//!
10//! ```
11//! use std::fs;
12//! use std::io::Read;
13//! use tempfile::TempDir;
14//! use tokio::runtime;
15//! use tokio_file::AioFileExt;
16//!
17//! let contents = b"abcdef";
18//! let mut rbuf = Vec::new();
19//!
20//! let dir = TempDir::new().unwrap();
21//! let path = dir.path().join("foo");
22//! let file = fs::OpenOptions::new()
23//! .create(true)
24//! .write(true)
25//! .open(&path)
26//! .unwrap();
27//! let rt = runtime::Builder::new_current_thread()
28//! .enable_io()
29//! .build()
30//! .unwrap();
31//! let r = rt.block_on(async {
32//! file.write_at(contents, 0).unwrap().await
33//! }).unwrap();
34//! assert_eq!(r, contents.len());
35//! drop(file);
36//!
37//! let mut file = fs::File::open(&path).unwrap();
38//! assert_eq!(file.read_to_end(&mut rbuf).unwrap(), contents.len());
39//! assert_eq!(&contents[..], &rbuf[..]);
40//! ```
41#![deny(missing_docs)]
42
43mod file;
44
45pub use file::{AioFileExt, ReadAt, ReadvAt, SyncAll, WriteAt, WritevAt};