DiffConfig

Struct DiffConfig 

Source
pub struct DiffConfig { /* private fields */ }
Expand description

Configuration for diff computation.

§Examples

use diffo::{DiffConfig, SequenceDiffAlgorithm};

let config = DiffConfig::new()
    .mask("*.password")
    .mask("api.secret")
    .float_tolerance("metrics.*", 1e-6)
    .collection_limit(500)
    .sequence_algorithm("users", SequenceDiffAlgorithm::Patience)
    .default_sequence_algorithm(SequenceDiffAlgorithm::IndexBased);

Implementations§

Source§

impl DiffConfig

Source

pub fn new() -> Self

Create a new configuration with default settings.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new();
Source

pub fn ignore(self, pattern: &str) -> Self

Ignore changes at matching paths.

Supports glob patterns like *.password or database.*.credentials.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .ignore("internal.*")
    .ignore("*.temp");
Source

pub fn mask(self, pattern: &str) -> Self

Mask values at matching paths.

Masked values will show as “***” in output instead of actual values.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .mask("*.password")
    .mask("api.secret");
Source

pub fn float_tolerance(self, pattern: &str, tolerance: f64) -> Self

Set float tolerance for specific paths.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .float_tolerance("metrics.*.value", 1e-6);
Source

pub fn default_float_tolerance(self, tolerance: f64) -> Self

Set default float tolerance for all floats.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .default_float_tolerance(1e-9);
Source

pub fn max_depth(self, depth: usize) -> Self

Set maximum traversal depth.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .max_depth(32);
Source

pub fn collection_limit(self, limit: usize) -> Self

Set maximum collection size to diff.

Collections larger than this limit will be elided.

§Examples
use diffo::DiffConfig;

let config = DiffConfig::new()
    .collection_limit(500);
Source

pub fn sequence_algorithm( self, pattern: &str, algorithm: SequenceDiffAlgorithm, ) -> Self

Set sequence diff algorithm for specific paths.

§Examples
use diffo::{DiffConfig, SequenceDiffAlgorithm};

let config = DiffConfig::new()
    .sequence_algorithm("users", SequenceDiffAlgorithm::Patience)
    .sequence_algorithm("logs.*", SequenceDiffAlgorithm::Myers);
Source

pub fn default_sequence_algorithm( self, algorithm: SequenceDiffAlgorithm, ) -> Self

Set default sequence diff algorithm.

§Examples
use diffo::{DiffConfig, SequenceDiffAlgorithm};

let config = DiffConfig::new()
    .default_sequence_algorithm(SequenceDiffAlgorithm::Myers);
Source

pub fn comparator(self, pattern: &str, comparator: Comparator) -> Self

Add a custom comparator for a specific path pattern.

When comparing values at paths matching the pattern, the comparator will be called first. If it returns true, values are considered equal and no diff is recorded. If it returns false, normal diffing proceeds.

Uses glob patterns for matching. Note: Array indices like [0], [1] require workaround patterns (e.g., ?0?, ?1?) due to glob syntax treating [] as character classes.

§Examples
use diffo::{DiffConfig, ValueExt};
use std::rc::Rc;

let config = DiffConfig::new()
    // Field-level comparison
    .comparator("url", Rc::new(|old, new| {
        if let (Some(a), Some(b)) = (old.as_string(), new.as_string()) {
            a.to_lowercase() == b.to_lowercase()
        } else {
            old == new
        }
    }))
    // Array element (workaround pattern)
    .comparator("?0?", Rc::new(|old, new| {
        old.get_field("id") == new.get_field("id")
    }));

Trait Implementations§

Source§

impl Clone for DiffConfig

Source§

fn clone(&self) -> DiffConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DiffConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DiffConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.