use config::ConfigError;
use serde_derive::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct GeneratorConfig {
pub expand_limit: Option<u32>,
pub soft_limit: usize,
pub hard_limit: usize,
pub limit_depth_level: usize,
pub text_expand_limit: String,
pub benchmark_mode: bool,
_dummy: bool,
pub upper_bound_zero_or_more_repetition: u32,
pub upper_bound_one_or_more_repetition: u32,
pub upper_bound_at_least_repetition: u32,
pub max_attempts_negation: u32,
}
impl GeneratorConfig {
pub fn new(config_file: &str) -> Result<Self, ConfigError> {
let mut settings = config::Config::default();
settings
.merge(config::File::with_name("src/config/default.toml"))
.unwrap()
.merge(config::File::with_name(config_file))
.unwrap()
.merge(config::Environment::with_prefix("APP"))
.unwrap();
settings.try_into()
}
pub fn benchmark() -> Self {
let mut settings: Self = Default::default();
settings.benchmark_mode = true;
settings
}
}
impl Default for GeneratorConfig {
fn default() -> Self {
GeneratorConfig {
expand_limit: None,
soft_limit: 10000,
hard_limit: 25000,
limit_depth_level: 200,
text_expand_limit: "".to_string(),
_dummy: false,
benchmark_mode: false,
upper_bound_zero_or_more_repetition: 5,
upper_bound_one_or_more_repetition: 5,
upper_bound_at_least_repetition: 10,
max_attempts_negation: 100,
}
}
}