Skip to main content

Module diff

Module diff 

Source
Expand description

C0DIFF: atomic multi-file edits with anchored patterns (DIFF.md). A diff is an ordinary document of shape diff: files of records, each record a pattern of units, with old␚␟new (the sub-unit of old) as the substitution.

use std::collections::HashMap;
let diff = c0::diff::build(|d| {
    d.file("greeting.txt", |d| {
        d.record(|r| {
            r.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 C0DIFF document.
FileEdit
A file’s records, in order.
Pattern
One record: an anchored pattern.
PatternBuilder
Builds the units of one record.
Unit
One unit of a pattern: an anchor (new is None) or a substitution.

Enums§

DiffError
Errors raised while parsing or applying a C0DIFF.

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 records (DIFF.md “Records”): each search text must match once from the cursor to the end of the file.
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), refusing everything DIFF.md lists under “What a diff may not hold”.