ConfigDiff

Struct ConfigDiff 

Source
pub struct ConfigDiff;
Expand description

Configuration diff utilities for detecting differences between configurations

This utility provides methods to compare configuration instances and detect what fields have changed. Useful for configuration hot-reload, migration, auditing, and change tracking.

§Examples

use chie_shared::{ConfigDiff, RetryConfig};

let old_config = RetryConfig::default();
let mut new_config = RetryConfig::default();
new_config.max_attempts = 10;

let changes = ConfigDiff::retry_config(&old_config, &new_config);
assert_eq!(changes.len(), 1);
assert_eq!(changes[0].field, "max_attempts");
assert_eq!(changes[0].new_value, "10");

Implementations§

Source§

impl ConfigDiff

Source

pub fn network_config( old: &NetworkConfig, new: &NetworkConfig, ) -> Vec<ConfigChange>

Detect differences between two NetworkConfig instances

Returns a list of changes between the old and new configurations. Compares all fields including max_connections, timeouts, relay/DHT settings, bootstrap peers, and listen addresses.

§Examples
use chie_shared::{ConfigDiff, NetworkConfig};

let old = NetworkConfig::default();
let mut new = NetworkConfig::default();
new.max_connections = 200;
new.enable_relay = false;

let changes = ConfigDiff::network_config(&old, &new);
assert_eq!(changes.len(), 2);

// Check for specific changes
let fields: Vec<&str> = changes.iter().map(|c| c.field.as_str()).collect();
assert!(fields.contains(&"max_connections"));
assert!(fields.contains(&"enable_relay"));
Source

pub fn retry_config(old: &RetryConfig, new: &RetryConfig) -> Vec<ConfigChange>

Detect differences between two RetryConfig instances

Returns a list of changes between the old and new configurations.

§Examples
use chie_shared::{ConfigDiff, RetryConfigBuilder};

let old = RetryConfigBuilder::new()
    .max_attempts(3)
    .initial_backoff_ms(100)
    .build();

let new = RetryConfigBuilder::new()
    .max_attempts(5)
    .initial_backoff_ms(200)
    .build();

let changes = ConfigDiff::retry_config(&old, &new);
assert_eq!(changes.len(), 2);

// Verify specific changes
let max_attempts_change = changes.iter()
    .find(|c| c.field == "max_attempts")
    .unwrap();
assert_eq!(max_attempts_change.old_value, "3");
assert_eq!(max_attempts_change.new_value, "5");
Source

pub fn feature_flags( old: &FeatureFlags, new: &FeatureFlags, ) -> Vec<ConfigChange>

Detect differences between two FeatureFlags instances

Returns a list of changes between the old and new configurations.

§Examples
use chie_shared::{ConfigDiff, FeatureFlagsBuilder};

let old = FeatureFlagsBuilder::new()
    .experimental(false)
    .debug_mode(false)
    .build();

let new = FeatureFlagsBuilder::new()
    .experimental(true)
    .debug_mode(true)
    .performance_profiling(true)
    .build();

let changes = ConfigDiff::feature_flags(&old, &new);
assert!(changes.len() >= 2);  // At least experimental and debug_mode changed

// Check for experimental flag change
let exp_change = changes.iter()
    .find(|c| c.field == "experimental")
    .unwrap();
assert_eq!(exp_change.old_value, "false");
assert_eq!(exp_change.new_value, "true");

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> 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, 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.