Main exports
Compare bytes
diff_with_tier(old: &[u8], new: &[u8], old_path: &str, new_path: &str, presence: SourcePresence) -> TierDiffResult compares original bytes before decoding text. Presence distinguishes empty files from missing files. Set old_exists or new_exists to false for whole-file additions/deletions.
TierDiffResult exposes changes, fallback: Option<String>, node_count, and tier. JSON serializes the tier as a number from zero to five.
classify_file(path) returns FileInfo { path, extension, tier }. is_parseable(path) reports whether a semantic parser is available. Classification alone does not promise a linked grammar.
Parsing APIs
parse_code(source, extension, max_nodes)returns a parsed tree orParseError.parse_data_as(source, extension)selects JSON/JSONC/JSON5, YAML, TOML, INI, or environment syntax by format.parse_data(source)supplies format inference for callers without a path.tree_from_value(&serde_json::Value)returns a typed value tree.parse_markup(source)returns an element/attribute tree.list_languages()returns language names, semantic levels, and extensions;has_grammar(extension)checks availability.
Result<Arc<Tree>, ParseError>. Typed scalar metadata preserves changes such as numeric 1 to string "1". Markup attributes include href and other non-label attributes. YAML supports nested indentation through its format parser.
Sequence helpers diff_lines and diff_words trim equal boundaries, use exact LCS for small inputs, and use bounded Myers processing for larger inputs. If the work budget runs out, unique unchanged anchors divide the remaining input into smaller gaps for positional comparison. Code/data/markup parser failures fall back directly to raw lines. Consult source constants and benchmarks for analysis budgets.
Binary plugins implement BinaryDiffPlugin and register through register_binary_plugin. The default adapter still reports changed bytes when no plugin answers. Byte identity is never inferred from lossy text decoding.
Classify and parse code
has_grammar and parse_code. The
code Cargo feature is enabled by default. With it disabled, the library still
provides data, markup, prose, lines, and binary handling, but no linked code
grammars.
File presence and whole-file edits
SourcePresence::default() means both files exist, even if a source slice is
empty. Set the absent side explicitly when collecting file additions/removals:
Parse cache
Each native worker reuses its parser instances and a bounded content cache. Cache entries require both content hash and full source equality. A thread keeps at most 64 entries, 50,000 cached nodes, and 2,000,000 source bytes; oversized trees are not cached. Cache state is process-local and thread-local, so a new CLI process does not inherit it.parse_cache_stats() inspects the calling thread;
clear_parse_cache() drops its cached trees while keeping reusable parsers.
Binary plugin contract
A plugin gets original bytes. It returnsOk(Some(actions)) to answer,
Ok(None) to decline, or an error if it cannot process the input. Empty answers,
errors, and panics do not hide changed bytes; the router can try the next plugin
and retain the default byte-length report.
This complete example registers a plugin that declines .bin inputs, allowing
the default handling to continue: