use deepmerge::prelude::*;
fn main() {
println!("=== Basic Usage Example ===\n");
demo_basic_usage();
}
fn demo_basic_usage() {
#[derive(DeepMerge, Debug)]
struct Config {
pub title: String,
pub tags: Vec<String>,
pub enabled: bool,
pub version: String,
}
let mut config = Config {
title: "My App".to_string(),
tags: vec!["web".to_string()],
enabled: false,
version: "1.0".to_string(),
};
let update = Config {
title: " v2".to_string(),
tags: vec!["api".to_string()],
enabled: true,
version: "2.0".to_string(),
};
println!("Before merge:");
println!(" title: {:?}", config.title);
println!(" tags: {:?}", config.tags);
println!(" enabled: {}", config.enabled);
println!(" version: {:?}", config.version);
println!("\nUpdate values:");
println!(" title: {:?}", update.title);
println!(" tags: {:?}", update.tags);
println!(" enabled: {}", update.enabled);
println!(" version: {:?}", update.version);
let policy = ComposedPolicy::new(DefaultPolicy)
.with_string_merge(StringMerge::Concat)
.with_sequence_merge(SequenceMerge::Append)
.with_bool_merge(BoolMerge::TrueWins);
config.merge_with_policy(update, &policy);
println!("\nAfter merge:");
println!(" title: {:?} (concatenated using custom policy)", config.title);
println!(" tags: {:?} (appended using custom policy)", config.tags);
println!(" enabled: {} (true wins using custom policy)", config.enabled);
println!(" version: {:?} (concatenated using custom policy)", config.version);
assert_eq!(config.title, "My App v2");
assert_eq!(config.tags, vec!["web", "api"]);
assert_eq!(config.enabled, true);
assert_eq!(config.version, "1.02.0");
println!("\n✓ All assertions passed! Example matches README documentation.");
}