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§
- Diff
Builder - Writes a C0DIFF document.
- File
Edit - A file’s records, in order.
- Pattern
- One record: an anchored pattern.
- Pattern
Builder - Builds the units of one record.
- Unit
- One unit of a pattern: an anchor (
newisNone) or a substitution.
Enums§
- Diff
Error - 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 diffheading). - parse
- Parse a diff document (with or without its SYN heading), refusing everything DIFF.md lists under “What a diff may not hold”.