Skip to main content

apply_entry_patches

Function apply_entry_patches 

Source
pub fn apply_entry_patches(
    data: &[EntryOptions],
    patches: &[PatchOptions],
    warn: impl FnMut(&str),
) -> Vec<EntryOptions>
Expand description

Apply patch rows to an entry list — THE patch semantics of this crate, shared by mounting, recomposition, and offline config tooling so a dump can never drift from what boots.

Semantics (a direct port of upstream applyEntryPatches):

  • The result is fully detached from both inputs, even when patches is empty. Recomposition must always restart from the original patch data.
  • The id index is built once from data (recursing into groups) and extended only by insert rows as they are added, so a later patch in the same list can target a row an earlier patch inserted — and rows that appear any other way (inside a replaced config, say) stay invisible to it.
  • insert with id appends to that group’s children (the target must be a group); insert without id appends to the top level.
  • Non-insert patches require id. name, when present and non-empty, must equal the target’s name. config, disabled, and inject replace the target’s fields wholesale.
  • A patch that matches nothing — missing id, unknown target, name mismatch, non-group insert target — warns through warn and is skipped, never an error: one overlay shared across surfaces does not have to match every tree.
  • Override keys with no Rust slot (group, intercept, isolate, anything unknown) warn and are skipped.

§Example

use cordis_include::{apply_entry_patches, EntryOptions, Node, PatchOptions};

let base = vec![EntryOptions::new("adapter-http").with_id("http")];
let patches = vec![PatchOptions {
    id: Some("http".into()),
    config: Some(Node::from_iter([(
        "port".to_string(),
        Node::Int(8080),
    )])),
    ..Default::default()
}];
let composed = apply_entry_patches(&base, &patches, |_| {});
assert_eq!(composed[0].config.as_ref().unwrap()["port"], Node::Int(8080));
// The input stays untouched: recomposition restarts from the originals.
assert!(base[0].config.is_none());