Skip to main content

rustledger_plugin/
lib.rs

1//! Beancount WASM Plugin Runtime.
2//!
3//! This crate provides a plugin system for extending Beancount's functionality.
4//! Plugins can be written in any language that compiles to WebAssembly, or as
5//! native Rust code for maximum performance.
6//!
7//! # Architecture
8//!
9//! The plugin system uses wasmtime as the WASM runtime with `MessagePack`
10//! serialization for passing data across the WASM boundary.
11//!
12//! # Plugin Types
13//!
14//! - **WASM Plugins**: Sandboxed plugins loaded from `.wasm` files
15//! - **Native Plugins**: Built-in plugins implemented in Rust
16//!
17//! # Built-in Plugins (31)
18//!
19//! See the [plugin reference](https://rustledger.github.io/docs/reference/plugins) for the full list.
20//!
21//! # Example
22//!
23//! ```ignore
24//! use rustledger_plugin::{PluginManager, PluginInput, PluginOptions};
25//!
26//! let mut manager = PluginManager::new();
27//! manager.load(Path::new("my_plugin.wasm"))?;
28//!
29//! let input = PluginInput {
30//!     directives: vec![],
31//!     options: PluginOptions::default(),
32//!     config: None,
33//! };
34//!
35//! let output = manager.execute_all(input)?;
36//! ```
37
38// Note: unsafe is needed for wasmtime Module::deserialize (caching compiled modules)
39#![deny(unsafe_code)]
40#![warn(missing_docs)]
41
42pub mod convert;
43pub mod dispatch;
44pub mod native;
45#[cfg(feature = "python-plugins")]
46pub mod python;
47#[cfg(feature = "wasm-runtime")]
48pub mod runtime;
49#[cfg(feature = "wasm-runtime")]
50pub mod sandbox;
51pub mod test_helpers;
52pub mod types;
53#[cfg(feature = "wasm-runtime")]
54pub mod wasm_dir_scan;
55
56pub use convert::{
57    ConversionError, directive_to_wrapper, directive_to_wrapper_with_location,
58    directives_to_wrappers, wrapper_to_directive, wrappers_to_directives,
59};
60pub use dispatch::{
61    PluginPass, PluginResolveError, PluginRunError, ResolvedPlugin, resolve_plugin,
62};
63pub use native::{
64    AUTO_ACCOUNTS_NAME, DOCUMENT_DISCOVERY_NAME, NativePlugin, NativePluginRegistry, RegularPlugin,
65    SynthPlugin, document_discovery_config,
66};
67#[cfg(feature = "wasm-runtime")]
68pub use runtime::{
69    Plugin, PluginManager, RuntimeConfig, WasmPluginDirScanReport, WatchingPluginManager,
70    validate_plugin_module,
71};
72pub use types::{
73    DirectiveWrapper, PluginError, PluginErrorSeverity, PluginInput, PluginOp, PluginOptions,
74    PluginOutput, validate_op_coverage,
75};