| Crates.io | deepmerge |
| lib.rs | deepmerge |
| version | 0.1.0 |
| created_at | 2025-09-10 23:51:01.255938+00 |
| updated_at | 2025-09-10 23:51:01.255938+00 |
| description | Deep merge functionality with policy-driven merging and derive macro support |
| homepage | https://github.com/jdx/deepmerge |
| repository | https://github.com/jdx/deepmerge |
| max_upload_size | |
| id | 1833141 |
| size | 350,494 |
A flexible deep merge library for Rust with policy-driven merging and derive macros featuring typed attributes.
DeepMerge for your structsalloc)Add this to your Cargo.toml:
[dependencies]
deepmerge = { version = "0.1", features = ["derive"] }
use deepmerge::prelude::*;
// Use clean identifier syntax instead of string literals
#[derive(DeepMerge, Debug)]
#[merge(policy(string = concat, sequence = append, bool = true_wins))]
struct Config {
pub title: String,
pub tags: Vec<String>,
pub enabled: bool,
// Field-level override
#[merge(string = keep)]
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(),
};
config.merge_with_policy(update, &DefaultPolicy);
// Results:
// title: "My App v2" (concatenated)
// tags: ["web", "api"] (appended)
// enabled: true (true wins)
// version: "1.0" (kept original due to field-level override)
use deepmerge::prelude::*;
#[derive(DeepMerge)]
#[merge(policy(
// String literals (traditional)
string = "concat",
// Identifiers (new, cleaner syntax)
sequence = append,
bool = true_wins,
number = sum,
// Mixed syntax is supported
map = "overlay"
))]
struct FlexibleConfig { /* ... */ }
String Policies: concat, keep, replace
Sequence Policies: append, prepend, union, extend, intersect
Boolean Policies: true_wins, false_wins, replace, keep
Number Policies: sum, max, min, replace, keep
Map Policies: overlay, union, left, right
Option Policies: take, preserve, or_left
Policies are applied in this order of precedence:
The infrastructure is ready for advanced path expressions:
// Coming soon:
// #[merge(policy(string = StringMerge::ConcatWithSep(", ")))]
// Coming soon:
// #[merge(policy(condition = changed, changed_by = "key_extractor_fn"))]
derive (default): Enable the derive macrostd (default): Enable standard library supportalloc (default): Enable allocation supportindexmap: Add support for IndexMap typesLicensed under either of:
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.