Expand description
§tanzim-merge
Package | Documentation | Repository
Third stage of the tanzim pipeline: groups parsed payloads by entry name and merges their values.
§The Merge trait
Implement Merge to define a custom merge strategy. The output is
Merged — a HashMap<Option<String>, (Vec<Payload>, LocatedValue)> keyed by entry
name, where the Vec<Payload> records which payloads contributed to each merged
value.
§Grouping key
Payload::maybe_name determines the map key:
Some("foo")→ keySome("foo")None→ keyNone(all unnamed payloads share this bucket)
§Built-in strategies
| Type | Behaviour |
|---|---|
LastWins | Last value for each name fully replaces any previous value |
DeepMerge | Maps are merged recursively; the overlay value wins at each non-map leaf |
§Example
use tanzim_merge::{DeepMerge, LastWins, Merge};
use tanzim_load::Payload;
use tanzim_source::Source;
use tanzim_value::{LocatedValue, Location, Map, Value};
let source = Source::parse("env").unwrap();
let make_entry = |name: Option<&str>, key: &str, val: &str| {
let loc = Location::at("env", "", None, None, None);
let mut map = Map::new();
map.insert(key.to_string(), LocatedValue::new(Value::String(val.to_string()), loc.clone()));
let payload = Payload {
source: source.clone(),
maybe_name: name.map(str::to_string),
maybe_format: Some("env".into()),
content: vec![],
};
(payload, LocatedValue::new(Value::Map(map), loc))
};
let list = vec![
make_entry(Some("db"), "host", "primary"),
make_entry(Some("db"), "host", "replica"),
];
// LastWins: second entry fully replaces the first
let merged = LastWins.merge(&list).unwrap();
let db = merged.get(&Some("db".to_string())).unwrap();
let host = db.1.value().as_map().unwrap().get("host").unwrap();
assert_eq!(host.value().as_string().unwrap(), "replica");§Features
No default features. Opt-in logging / tracing emit log messages / trace
spans via the log / tracing crates.
§Relations
- Consumes
LocatedValuefromtanzim-parse. - Uses
Payloadfromtanzim-load(which embedsSource) to track provenance. - Full pipeline wired in
tanzim.
Structs§
- Deep
Merge - Deep-merge merger: maps with the same name are merged recursively.
- Last
Wins - Last-write-wins merger: each name keeps only its last-seen value.
Enums§
- Error
- Merge error type.
Traits§
- Merge
- Merges parsed payloads grouped by entry name.
Type Aliases§
- Merged
- Merge result: entry name → (contributing payloads, merged value).