Skip to main content

read_json_file

Function read_json_file 

Source
pub fn read_json_file<T: DeserializeOwned>(
    path: &Path,
) -> Result<T, ReadJsonError>
Expand description

Reads a JSON file from disk and deserializes it into T.

This replaces the common boilerplate of fs::read_to_string followed by serde_json::from_str, with error messages that include the file path.

§Errors

Returns ReadJsonError::Read if the file cannot be read, or ReadJsonError::Parse if the contents are not valid JSON for T.

§Example

use perfgate_types::read_json_file;
use perfgate_types::RunReceipt;
use std::path::Path;

let receipt: RunReceipt = read_json_file(Path::new("run.json")).unwrap();