rustledger-plugin-types
WASM plugin interface types for rustledger.
This crate provides the canonical type definitions that plugins must use to communicate with the rustledger host. Using this crate ensures your plugin's types are always compatible with the host.
Installation
Add to your plugin's Cargo.toml:
[]
= "my-plugin"
= "2021"
[]
= ["cdylib"]
[]
= "0.10"
= "1"
Version compatibility: Use the same minor version as your target rustledger host (e.g., 0.10.x types for rustledger 0.10.x).
Quick Start
use *;
pub extern "C"
pub extern "C"
/// Helper to return an error response
Pure pass-through validators that emit no transformations can build the op list with the convenience constructor:
let output = passthrough;
Building
# Install WASM target
# Build your plugin
The plugin will be at target/wasm32-unknown-unknown/release/my_plugin.wasm.
Using Your Plugin
In your beancount file:
plugin "path/to/my_plugin.wasm" "optional-config-string"
2024-01-01 open Assets:Bank USD
Types Overview
| Type | Description |
|---|---|
PluginInput |
Input from host: directives, options, config |
PluginOutput |
Output to host: ops: Vec<PluginOp> describing the resulting directive list, plus errors |
PluginOp |
One Keep/Modify/Insert/Delete operation against the input |
DirectiveWrapper |
Wrapper with date, source location, and data |
DirectiveData |
Enum of all directive types |
PluginError |
Error/warning with optional source location |
PluginOp Variants
PluginOutput.ops is an ordered list of operations, not a replacement
directive list. Every input index must appear in exactly one of
Keep, Modify, or Delete; the host validates this and emits a
plugin error if violated.
| Variant | Semantics |
|---|---|
Keep(i) |
Reuse input[i] unchanged. Span and file_id preserved. |
Modify(i, wrapper) |
Replace input[i]'s content with wrapper, inheriting input[i]'s source identity so errors still point at the original line. |
Insert(wrapper) |
Emit a fresh directive with synthesized location (SYNTHESIZED_FILE_ID, zero span). Use for directives the plugin invents. |
Delete(i) |
Drop input[i]. Must be explicit — omitting an index is a protocol violation. |
Creating Errors
use ;
// Simple error
let error = error;
// Warning with source location
let warning = warning
.at;
Memory Management
Plugins must export:
alloc(size: u32) -> *mut u8- Required. The host calls this to allocate memory for input data.
Plugins may optionally export:
dealloc(ptr: *mut u8, size: u32)- Optional. For freeing memory within the plugin.
License
GPL-3.0-only