tiger-lib 1.17.0

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
use std::borrow::Cow;
use std::fs::read_to_string;
use std::path::{Path, PathBuf};

use anyhow::Result;
use serde::Deserialize;

use crate::helpers::TigerHashMap;
use crate::report::ErrorKey;
use crate::report::errors::Errors;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SuppressionKey<'a> {
    pub key: ErrorKey,
    pub message: Cow<'a, str>,
}

pub type Suppression = Vec<SuppressionLocation>;

#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
pub struct SuppressionLocation {
    pub path: PathBuf,
    pub line: Option<String>,
    pub tag: Option<String>,
}

/// This picks out the fields we need from the json reports
#[derive(Deserialize)]
struct JsonReport {
    key: ErrorKey,
    message: String,
    locations: Vec<SuppressionLocation>,
}

pub fn suppress_from_json(fullpath: &Path) -> Result<()> {
    let reports: Vec<JsonReport> = serde_json::from_str(&read_to_string(fullpath)?)?;
    let mut suppress: TigerHashMap<SuppressionKey, Vec<Suppression>> = TigerHashMap::default();
    for JsonReport { key, message, locations } in reports {
        suppress
            .entry(SuppressionKey { key, message: Cow::Owned(message) })
            .or_default()
            .push(locations);
    }
    Errors::get_mut().suppress = suppress;
    Ok(())
}