The diffr plugin contract in Rust. wit/plugin.wit in the diffr
repository is the contract; this crate is its one Rust form, shared by
every plugin whether diffr compiles it in or runs it as a WASM component.
- [
types] holds the contract's records: the file entry, each side's flat preorder region list with parent ids and text, and the moves. They are generated fromwit/plugin.wititself, so there is one definition of each, and a plugin hands diffr the same records natively and as a component. - [
Plugin] is the one trait every plugin implements:new, which makes it from its options,queries, thenclassifyandmutate, taking and returning exactly those records. - [
host] holds what diffr gives every plugin:git. - [
export!] makes a plugin thepluginresource a component exports when the crate is built forwasm32-wasip2, and otherwise exposes its native registration for the host to collect. The same source builds both ways.
Plugins reason about regions with the same code:
- [
tree] rebuilds a side's list as a tree ([tree::sides], which the SDK calls on the way in so a plugin is handed [Pairing] of [Source] rather than the flat records) and holds the helpers for reading trees ([walk], [OtherSide], [one_sided], [docstring_of], and the rest). - [
apply] carries moves out. diffr carries every plugin's moves out with it, so [Draft], which carries a plugin's moves out on a copy as it makes them, and [apply::Fresh], which predicts fresh ids, give a plugin exactly the ids diffr will.