Function async_fs::read

source · []
pub async fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>>
Expand description

Reads the entire contents of a file as raw bytes.

This is a convenience function for reading entire files. It pre-allocates a buffer 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 a string, use read_to_string() instead.

Errors

An error will be returned in the following situations:

  • path does not point to an existing file.
  • The current process lacks permissions to read the file.
  • Some other I/O error occurred.

Examples

let contents = async_fs::read("a.txt").await?;