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 (14)
18//!
19//! - `implicit_prices`: Generates price entries from transaction costs/prices
20//! - `check_commodity`: Verifies all commodities are declared
21//! - `auto_accounts`: Auto-generates Open directives for used accounts
22//! - `auto_tag`: Auto-tag transactions by account patterns
23//! - `leafonly`: Errors on postings to non-leaf accounts
24//! - `noduplicates`: Hash-based duplicate transaction detection
25//! - `onecommodity`: Enforces single commodity per account
26//! - `unique_prices`: One price per day per currency pair
27//! - `check_closing`: Zero balance assertion on account closing
28//! - `close_tree`: Closes descendant accounts automatically
29//! - `coherent_cost`: Enforces cost OR price (not both) consistency
30//! - `sellgains`: Cross-checks capital gains against sales
31//! - `pedantic`: Enables all strict validation rules
32//! - `unrealized`: Calculates unrealized gains/losses
33//!
34//! # Example
35//!
36//! ```ignore
37//! use rustledger_plugin::{PluginManager, PluginInput, PluginOptions};
38//!
39//! let mut manager = PluginManager::new();
40//! manager.load(Path::new("my_plugin.wasm"))?;
41//!
42//! let input = PluginInput {
43//!     directives: vec![],
44//!     options: PluginOptions::default(),
45//!     config: None,
46//! };
47//!
48//! let output = manager.execute_all(input)?;
49//! ```
50
51// Note: unsafe is needed for wasmtime Module::deserialize (caching compiled modules)
52#![deny(unsafe_code)]
53#![warn(missing_docs)]
54
55pub mod convert;
56pub mod native;
57#[cfg(feature = "python-plugins")]
58pub mod python;
59#[cfg(feature = "wasm-runtime")]
60pub mod runtime;
61pub mod types;
62
63pub use convert::{
64    ConversionError, directive_to_wrapper, directives_to_wrappers, wrapper_to_directive,
65    wrappers_to_directives,
66};
67pub use native::{NativePlugin, NativePluginRegistry};
68#[cfg(feature = "wasm-runtime")]
69pub use runtime::{
70    Plugin, PluginManager, RuntimeConfig, WatchingPluginManager, validate_plugin_module,
71};
72pub use types::{PluginError, PluginErrorSeverity, PluginInput, PluginOptions, PluginOutput};