read_to_string_opt
Reads a whole file as text, giving None instead of an error when it does not exist.
Every other failure (permissions, a directory, invalid UTF-8) is still an error: only “not found” means “no value”.
Import
Section titled “Import”Cargo feature fs (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
path | impl AsRef<Path> | The file to read. |
Returns
Section titled “Returns”io::Result<Option<String>>
Errors
Section titled “Errors”Any io::Error from std::fs::read_to_string except io::ErrorKind::NotFound.
