twips 0.12.2

Twizzle Pattern Searcher — Twisty puzzle search library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use std::{fs::read_to_string, path::Path};

use serde::Deserialize;

use crate::_internal::errors::ArgumentError;

pub fn read_to_json<T: for<'a> Deserialize<'a>>(input_file: &Path) -> Result<T, ArgumentError> {
    let input_str = read_to_string(input_file).or(Err("Could not read input file."))?;
    let input_parsed: T =
        serde_json::from_str(&input_str).or(Err("Input file is not valid JSON."))?;
    Ok(input_parsed)
}