Skip to main content

patch_tape

Function patch_tape 

Source
pub fn patch_tape<T: TapeSource>(
    source_tape: &T,
    diff: &TapeDiff<'_>,
) -> Result<Value>
Expand description

Full pipeline: apply diff from tape_b to value derived from tape_a

This is the common use case for cross-format patching:

  1. Parse both documents as tapes
  2. Compute diff between tapes (fast!)
  3. Convert source tape to Value
  4. Apply diff to Value

§Example

let tape_a = UnifiedTape::parse(yaml_a.as_bytes(), FormatKind::Yaml)?;
let tape_b = UnifiedTape::parse(yaml_b.as_bytes(), FormatKind::Yaml)?;

let diff = diff_tapes(&tape_a, &tape_b)?;
let patched = patch_tape(&tape_a, &diff)?;
// patched is now equivalent to tape_b's data

§Errors

Returns an error if the source tape cannot be converted or the diff cannot be applied.