[][src]Function tokio::fs::write

pub fn write<P, C>(path: P, contents: C) -> WriteFile<P, C> where
    C: AsRef<[u8]>,
    P: AsRef<Path> + Send + 'static, 

Creates a future that will open a file for writing and write the entire contents of contents to it.

This is the async equivalent of std::fs::write.

Examples

use tokio::prelude::Future;
fn main() {
    let buffer = b"Hello world!";
    let task = tokio::fs::write("foo.txt", buffer).map(|data| {
        // `data` has now been written to foo.txt. The buffer is being
        // returned so it can be used for other things.
        println!("foo.txt now had {} bytes written to it", data.len());
    }).map_err(|e| {
        // handle errors
        eprintln!("IO error: {:?}", e);
    });
    tokio::run(task);
}