Skip to main content

Module diff

Module diff 

Source
Expand description

C0-DIFF: atomic multi-file edits with anchored patterns (DIFF.md).

use std::collections::HashMap;
let diff = c0::diff::build(|d| {
    d.file("greeting.txt", |d| {
        d.section(|s| {
            s.anchor("Hello ").sub("world", "universe").anchor("!");
        });
    });
    d.eot();
});
let mut files = HashMap::new();
files.insert("greeting.txt".to_string(), "Hello world!".to_string());
let out = c0::diff::apply(&diff, &files).unwrap();
assert_eq!(out["greeting.txt"], "Hello universe!");

Structs§

DiffBuilder
Writes a C0-DIFF document.
FileEdit
A file’s edits: replace-alls before any section apply from the start of the file to the first section’s match.
Section
A section: one anchored pattern, plus the replace-alls that follow it.
SectionBuilder
Builds the units of one section.
Unit
One unit of a pattern: an anchor (new is None) or a substitution.

Enums§

DiffError
Errors raised while parsing or applying a C0-DIFF.

Functions§

apply
Apply a diff to in-memory text files. Validates everything first and fails without touching anything on any error. Files the diff does not name pass through unchanged.
apply_bytes
Apply a diff to in-memory binary files; see apply.
apply_file
Apply one file’s edits (DIFF.md “Sections”, “Replace-all”).
apply_files
Apply a diff to files on disk under base_dir, atomically: every file is validated before any is written, and each is written through a temporary file and a rename.
build
Build a diff document (with its shape diff heading).
parse
Parse a diff document (with or without its SYN heading).