Skip to main content

read_file_safe

Function read_file_safe 

Source
pub fn read_file_safe(path: &Path) -> PatternsResult<String>
Expand description

Safely read a file with size limits and UTF-8 validation.

This function:

  1. Validates the file path
  2. Checks file size against limits
  3. Reads the file content
  4. Validates UTF-8 encoding

§Arguments

  • path - The path to the file to read

§Returns

The file contents as a String if successful.

§Errors

  • PatternsError::FileNotFound if file doesn’t exist
  • PatternsError::FileTooLarge if file exceeds MAX_FILE_SIZE
  • PatternsError::ParseError if file is not valid UTF-8
  • PatternsError::Io for other IO errors