file_to_key_value_map

Function file_to_key_value_map 

Source
pub fn file_to_key_value_map(
    path: &Path,
) -> Result<HashMap<Box<str>, Box<str>>, Error>
Expand description

Parses a key-value file into a hash map.

The function reads a text file where each non-empty line contains a key-value pair separated by whitespace. The first whitespace character on each line separates the key from the value.

§Format Rules

  • Keys cannot contain whitespace
  • Values can contain any characters (leading/trailing whitespace is trimmed)
  • Empty lines and lines without whitespace are ignored
  • Keys must be unique (duplicate keys result in an error)

§Arguments

  • path - Path to the key-value file to parse

§Returns

Returns a hash map on success, or an error on failure.

§Errors

This function will return an error if:

  • The file cannot be opened (Error::OpeningFile)
  • An I/O error occurs while reading (Error::ReadingFile)
  • A duplicate key is found in the file (Error::MultipleKeys)