Function async_std::fs::read_to_string[][src]

pub async fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String>

Reads the entire contents of a file as a string.

This is a convenience function for reading entire files. It pre-allocates a string based on the file size when available, so it is typically faster than manually opening a file and reading from it.

If you want to read the contents as raw bytes, use read instead.

This function is an async version of std::fs::read_to_string.

Errors

An error will be returned in the following situations:

Examples

use async_std::fs;

let contents = fs::read_to_string("a.txt").await?;