pub mod custom_checks_cfg;
use crate::util::*;
pub trait CustomChecksOpt {
fn custom_checks(&'static self) -> Option<&'static CustomChecks>;
fn custom_checks_enabled(&'static self) -> bool;
fn generate_custom_checks_toml_enabled(&self) -> bool;
fn custom_checks_from_path(&self, toml_path: &PathBuf) -> CustomChecks {
let toml = fs::read_to_string(toml_path).expect("Failed to read TOML file");
toml::from_str(&toml).expect("Failed to parse TOML")
}
fn generate_custom_checks_toml(&self, file_name: &str) {
let toml =
descriptive_toml_derive::TomlConfig::to_string_pretty_toml(&CustomChecks::default());
fs::write(file_name, toml).expect("Failed to write TOML file");
}
fn cdps(&'static self) -> Option<u32>;
fn triggers_pht(&'static self) -> Option<u32>;
fn rdh_version(&'static self) -> Option<u8>;
fn chip_orders_ob(&'static self) -> Option<&[Vec<u8>]>;
fn chip_count_ob(&'static self) -> Option<u8>;
}
impl<T> CustomChecksOpt for &T
where
T: CustomChecksOpt,
{
fn custom_checks(&'static self) -> Option<&'static CustomChecks> {
(*self).custom_checks()
}
fn custom_checks_enabled(&'static self) -> bool {
(*self).custom_checks_enabled()
}
fn generate_custom_checks_toml_enabled(&self) -> bool {
(*self).generate_custom_checks_toml_enabled()
}
fn cdps(&'static self) -> Option<u32> {
(*self).cdps()
}
fn triggers_pht(&'static self) -> Option<u32> {
(*self).triggers_pht()
}
fn rdh_version(&'static self) -> Option<u8> {
(*self).rdh_version()
}
fn chip_orders_ob(&'static self) -> Option<&'static [std::vec::Vec<u8>]> {
(*self).chip_orders_ob()
}
fn chip_count_ob(&'static self) -> Option<u8> {
(*self).chip_count_ob()
}
}
impl<T> CustomChecksOpt for Box<T>
where
T: CustomChecksOpt,
{
fn custom_checks(&'static self) -> Option<&'static CustomChecks> {
(**self).custom_checks()
}
fn custom_checks_enabled(&'static self) -> bool {
(**self).custom_checks_enabled()
}
fn generate_custom_checks_toml_enabled(&self) -> bool {
(**self).generate_custom_checks_toml_enabled()
}
fn cdps(&'static self) -> Option<u32> {
(**self).cdps()
}
fn triggers_pht(&'static self) -> Option<u32> {
(**self).triggers_pht()
}
fn rdh_version(&'static self) -> Option<u8> {
(**self).rdh_version()
}
fn chip_orders_ob(&'static self) -> Option<&[Vec<u8>]> {
(**self).chip_orders_ob()
}
fn chip_count_ob(&'static self) -> Option<u8> {
(**self).chip_count_ob()
}
}
impl<T> CustomChecksOpt for Arc<T>
where
T: CustomChecksOpt,
{
fn custom_checks(&'static self) -> Option<&'static CustomChecks> {
(**self).custom_checks()
}
fn custom_checks_enabled(&'static self) -> bool {
(**self).custom_checks_enabled()
}
fn generate_custom_checks_toml_enabled(&self) -> bool {
(**self).generate_custom_checks_toml_enabled()
}
fn cdps(&'static self) -> Option<u32> {
(**self).cdps()
}
fn triggers_pht(&'static self) -> Option<u32> {
(**self).triggers_pht()
}
fn rdh_version(&'static self) -> Option<u8> {
(**self).rdh_version()
}
fn chip_orders_ob(&'static self) -> Option<&[Vec<u8>]> {
(**self).chip_orders_ob()
}
fn chip_count_ob(&'static self) -> Option<u8> {
(**self).chip_count_ob()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_write_toml_to_file_trait() {
let mock_file_name = "mock_test_custom_checks.toml";
let mock_config = MockConfig::default();
mock_config.generate_custom_checks_toml(mock_file_name);
fs::remove_file(mock_file_name).unwrap();
}
}