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§
- Diff
Builder - Writes a C0-DIFF document.
- File
Edit - 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.
- Section
Builder - Builds the units of one section.
- Unit
- One unit of a pattern: an anchor (
newisNone) or a substitution.
Enums§
- Diff
Error - 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 diffheading). - parse
- Parse a diff document (with or without its SYN heading).