use std::collections::HashMap;
pub struct DiffConfig {
match_config: MatchConfig,
default_array_mode: ArrayMatchMode,
default_ambiguous_strategy: AmbiguousMatchStrategy,
}
impl DiffConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_match_config(mut self, match_config: MatchConfig) -> Self {
self.match_config = match_config;
self
}
pub fn with_fallback_array_mode(mut self, mode: ArrayMatchMode) -> Self {
self.default_array_mode = mode;
self
}
pub fn with_fallback_ambiguous_strategy(mut self, strategy: AmbiguousMatchStrategy) -> Self {
self.default_ambiguous_strategy = strategy;
self
}
pub fn match_config(&self) -> &MatchConfig {
&self.match_config
}
pub fn default_array_mode(&self) -> &ArrayMatchMode {
&self.default_array_mode
}
pub fn default_ambiguous_strategy(&self) -> &AmbiguousMatchStrategy {
&self.default_ambiguous_strategy
}
}
impl Default for DiffConfig {
fn default() -> Self {
Self {
match_config: MatchConfig::default(),
default_array_mode: ArrayMatchMode::Index,
default_ambiguous_strategy: AmbiguousMatchStrategy::default(),
}
}
}
pub struct MatchConfig {
paths: HashMap<String, ArrayMatchConfig>,
}
impl MatchConfig {
pub fn new() -> Self {
Self {
paths: HashMap::new(),
}
}
pub fn with_config_at(mut self, path: &str, config: ArrayMatchConfig) -> Self {
self.paths.insert(path.to_owned(), config);
self
}
pub fn config_at(&self, path: &str) -> Option<&ArrayMatchConfig> {
self.paths.get(path)
}
}
impl Default for MatchConfig {
fn default() -> Self {
Self::new()
}
}
pub struct ArrayMatchConfig {
mode: ArrayMatchMode,
ambiguous_strategy: Option<AmbiguousMatchStrategy>,
}
impl ArrayMatchConfig {
pub fn new(mode: ArrayMatchMode) -> Self {
Self {
mode,
ambiguous_strategy: None,
}
}
pub fn with_ambiguous_strategy(mut self, strategy: AmbiguousMatchStrategy) -> Self {
self.ambiguous_strategy = Some(strategy);
self
}
pub fn mode(&self) -> &ArrayMatchMode {
&self.mode
}
pub fn ambiguous_strategy(&self) -> Option<&AmbiguousMatchStrategy> {
self.ambiguous_strategy.as_ref()
}
}
pub enum ArrayMatchMode {
Index,
Key(String),
Contains,
}
#[derive(Default)]
pub enum AmbiguousMatchStrategy {
#[default]
Strict,
BestMatch,
Silent,
}