1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
//! A flexible deep merge library for Rust with policy-driven merging and derive macros featuring typed attributes.
//!
//! This crate provides comprehensive deep merge functionality with compile-time configuration
//! through derive macros, policy-driven behavior, and support for complex data structures.
//!
//! # Features
//!
//! - **Policy-driven merging**: Configure how different types should be merged
//! - **Derive macro support**: Automatically implement `DeepMerge` for your structs
//! - **Typed attributes**: Use identifiers instead of string literals for better compile-time checking
//! - **Flexible attribute syntax**: Mix string literals, identifiers, and path expressions
//! - **Precedence rules**: Field-level > struct-level > caller-provided policies
//! - **Multiple merge strategies**: Append, prepend, union, concatenation, replacement, and more
//! - **No-std compatible**: Works without the standard library (with `alloc`)
//!
//! # Quick Start with Prelude
//!
//! For convenience, import everything you need with the prelude:
//!
//! ```rust
//! use deepmerge::prelude::*;
//!
//! #[derive(DeepMerge)]
//! struct AppConfig {
//! name: String,
//! port: u16,
//! }
//!
//! let mut config = AppConfig {
//! name: "myapp".to_string(),
//! port: 8080
//! };
//!
//! let update = AppConfig {
//! name: "newname".to_string(),
//! port: 9090
//! };
//!
//! config.merge(update);
//! assert_eq!(config.name, "newname");
//! assert_eq!(config.port, 9090);
//! ```
//!
//! # Basic Usage with Explicit Policies
//!
//! ```rust
//! use deepmerge::prelude::*;
//!
//! // Simple derive without policy attributes
//! #[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(),
//! };
//!
//! // Use explicit policy for complex merge behavior
//! 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);
//!
//! // Results:
//! assert_eq!(config.title, "My App v2"); // concatenated
//! assert_eq!(config.tags, vec!["web", "api"]); // appended
//! assert_eq!(config.enabled, true); // true wins
//! assert_eq!(config.version, "2.0"); // replaced (no field-level override available yet)
//! ```
//!
//! # Policy Configuration
//!
//! Currently, policy configuration is done through explicit `ComposedPolicy` usage.
//! Derive macro policy attributes are temporarily disabled due to trait system complexity.
//!
//! ```rust
//! use deepmerge::prelude::*;
//!
//! #[derive(DeepMerge)]
//! struct FlexibleConfig {
//! name: String,
//! items: Vec<i32>,
//! enabled: bool,
//! count: i32,
//! }
//!
//! // Configure policies explicitly
//! let policy = ComposedPolicy::new(DefaultPolicy)
//! .with_string_merge(StringMerge::Concat)
//! .with_sequence_merge(SequenceMerge::Append)
//! .with_bool_merge(BoolMerge::TrueWins)
//! .with_number_merge(NumberMerge::Sum)
//! .with_map_merge(MapMerge::Overlay);
//!
//! let mut config = FlexibleConfig { /* ... */ };
//! let update = FlexibleConfig { /* ... */ };
//! config.merge_with_policy(update, &policy);
//! ```
//!
//! # Available Merge Policies
//!
//! - **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`
//!
//! # Using the Prelude
//!
//! The prelude module provides all commonly used items in a single import:
//!
//! ```rust
//! // Import everything you need with one line
//! use deepmerge::prelude::*;
//!
//! // Now you have access to:
//! // - DeepMerge trait and derive macro
//! // - All policy types (DefaultPolicy, ComposedPolicy)
//! // - All merge strategy enums (StringMerge, SequenceMerge, etc.)
//! // - All convenience functions (deep_merge, merged, etc.)
//! ```
//!
//! For version stability, you can also import from a specific version:
//!
//! ```rust
//! use deepmerge::prelude::v1::*;
//! ```
//!
//! # Policy Usage
//!
//! Currently, policies are configured explicitly through `ComposedPolicy`.
//! This provides fine-grained control over merge behavior.
//!
//! ```rust
//! use deepmerge::prelude::*;
//!
//! #[derive(DeepMerge, Debug)]
//! struct App {
//! name: String,
//! count: i32,
//! }
//!
//! let mut a = App { name: "svc".into(), count: 2 };
//! let b = App { name: "new".into(), count: 3 };
//!
//! // Configure specific merge behavior
//! let policy = ComposedPolicy::new(DefaultPolicy)
//! .with_string_merge(StringMerge::Replace)
//! .with_number_merge(NumberMerge::Sum);
//!
//! a.merge_with_policy(b, &policy);
//! assert_eq!(a.name, "new"); // replaced
//! assert_eq!(a.count, 5); // summed (2 + 3)
//! ```
//!
//! ## Per-policy examples (concise)
//!
//! - String policies:
//! - Replace (default)
//! - Keep
//! - Concat / `ConcatWithSep`
//! ```rust
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! struct S { s: String }
//! let mut a = S { s: "a".into() };
//! let policy = ComposedPolicy::new(DefaultPolicy).with_string_merge(StringMerge::Concat);
//! a.merge_with_policy(S { s: "b".into() }, &policy);
//! assert_eq!(a.s, "ab");
//! ```
//!
//! - Number policies: Replace (default), Keep, Sum, Max, Min
//! ```rust
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! struct N { n: i32 }
//! let mut a = N { n: 2 };
//! let policy = ComposedPolicy::new(DefaultPolicy).with_number_merge(NumberMerge::Max);
//! a.merge_with_policy(N { n: 5 }, &policy);
//! assert_eq!(a.n, 5);
//! ```
//!
//! - Bool policies: Replace (default), Keep, `TrueWins`, `FalseWins`
//! ```rust
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! struct B { b: bool }
//! let mut a = B { b: false };
//! let policy = ComposedPolicy::new(DefaultPolicy).with_bool_merge(BoolMerge::TrueWins);
//! a.merge_with_policy(B { b: true }, &policy);
//! assert!(a.b);
//! ```
//!
//! - Sequence policies: Append (default), Prepend, Extend, Union, Intersect
//! ```rust
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! struct L { v: Vec<i32> }
//! let mut a = L { v: vec![1,2] };
//! let policy = ComposedPolicy::new(DefaultPolicy).with_sequence_merge(SequenceMerge::Append);
//! a.merge_with_policy(L { v: vec![2,3] }, &policy);
//! assert_eq!(a.v, vec![1,2,2,3]);
//! ```
//!
//! - Map policies: Overlay (default), Union, Left, Right
//! ```rust
//! use std::collections::HashMap;
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! #[merge(policy(map = overlay))]
//! struct M { m: HashMap<&'static str, i32> }
//! let mut a = M { m: [("a",1)].into_iter().collect() };
//! a.merge(M { m: [("a",2),("b",3)].into_iter().collect() });
//! assert_eq!(a.m.get("a"), Some(&2));
//! assert_eq!(a.m.get("b"), Some(&3));
//! ```
//!
//! - Option policies: Take (default), Preserve, `OrLeft`
//! ```rust
//! use deepmerge::prelude::*;
//! #[derive(DeepMerge, Debug)]
//! #[merge(policy(option = preserve))]
//! struct O { o: Option<i32> }
//! let mut a = O { o: Some(1) };
//! a.merge(O { o: Some(2) });
//! assert_eq!(a.o, Some(1));
//! ```
extern crate alloc;
pub use ;
// Re-export derive macro if feature is enabled
pub use DeepMerge;
// Top-level convenience functions
/// Deep merge two values using the default policy
/// Deep merge two values using a specific policy
/// Deep merge by reference using the default policy
/// Deep merge by reference using a specific policy
/// Merge two values and return a new merged value using the default policy
/// This provides parity with `deep_merge` but returns a new value instead of mutating
/// Merge two values and return a new merged value using a specific policy
/// Deep merge with change reporting using the default policy
/// Deep merge with change reporting using a specific policy
/// Deep merge from another type using the default policy
/// Deep merge from another type using a specific policy
/// Deep merge from another type with change reporting using the default policy
/// Deep merge from another type with change reporting using a specific policy
// Export Vec helper functions for deduplication and by-key operations
pub use ;
pub use ;
// Export Option helper functions for change detection
pub use ;