use deepmerge::{DeepMerge, DefaultPolicy};
#[derive(DeepMerge)]
struct UserProfile {
username: String,
email: String,
age: u32,
bio: String,
}
#[derive(DeepMerge)]
struct Application {
profile: UserProfile,
settings: AppSettings,
}
#[derive(DeepMerge)]
struct AppSettings {
theme: String,
notifications: bool,
language: String,
}
fn main() {
println!("=== DeepMerge without Clone or PartialEq ===\n");
let mut app = Application {
profile: UserProfile {
username: "alice".to_string(),
email: "alice@example.com".to_string(),
age: 25,
bio: "Software developer".to_string(),
},
settings: AppSettings {
theme: "light".to_string(),
notifications: true,
language: "en".to_string(),
},
};
let update = Application {
profile: UserProfile {
username: "alice_updated".to_string(),
email: "alice@newdomain.com".to_string(),
age: 26,
bio: "Senior software developer".to_string(),
},
settings: AppSettings {
theme: "dark".to_string(),
notifications: false,
language: "es".to_string(),
},
};
println!("Before merge:");
println!(" Username: {}", app.profile.username);
println!(" Email: {}", app.profile.email);
println!(" Theme: {}", app.settings.theme);
println!();
app.merge_with_policy(update, &DefaultPolicy);
println!("After merge:");
println!(" Username: {}", app.profile.username);
println!(" Email: {}", app.profile.email);
println!(" Theme: {}", app.settings.theme);
println!();
println!("✓ DeepMerge works without Clone or PartialEq!");
println!();
println!("Note: Clone is only needed if you want to use merge_ref()");
println!("Note: PartialEq is only needed for assert_eq!() in tests");
}