Skip to main content

read_file

Function read_file 

Source
pub fn read_file(path: &Path) -> Result<String>
Expand description

Reads a file from disk and returns its contents as a string.

§Arguments

  • path - The file path to read

§Returns

  • Ok(String) - The file contents
  • Err - If the file doesn’t exist, is too large, is binary, or is not valid UTF-8

§Behavior

  • Rejects files larger than 1 MB
  • Reads raw bytes first, then checks for binary content (null bytes)
  • Converts to UTF-8 only after binary check passes