API Reference
Complete API reference for Railguard's Rust crates.
Railguard is structured as a Cargo workspace with multiple crates. This reference covers the public APIs of each crate.
Crate Overview
| Crate | Description | Primary Exports |
|---|---|---|
rg-types | Shared data structures | Config, Verdict, Receipt, RpcRequest |
rg-policy | Policy engine | RuntimePolicy, inspect(), decode_raw_transaction() |
rg-proxy | HTTP/JSON-RPC server | AppState, start_server(), create_router() |
rg-cloud | Cloud integration | device_code_flow(), sync_policy(), push_receipts() |
Quick Links
- Types Reference — All data structures
- Policy Engine — Deep dive into inspection logic
- Configuration — Config file format
Usage Example
Error Handling
Railguard uses different error types depending on context:
| Crate | Error Type | Description |
|---|---|---|
rg-types | — | No errors (pure data) |
rg-policy | PolicyError | Config parsing, signature parsing |
rg-policy | DecodeError | RLP/ABI decoding failures |
rg-proxy | ProxyError | Server, client, config errors |
bin/rg | eyre::Report | Top-level error handling |
Example Error Handling
JSON-RPC Handling
Railguard implements JSON-RPC 2.0 with full spec compliance:
Thread Safety
All public types are designed for concurrent use:
RuntimePolicyisSend + Sync(wrapped inArcinAppState)AppStateisClone(usesArcinternally)- Event channels use
tokio::sync::mpsc
Feature Flags
| Feature | Description | Default |
|---|---|---|
simulation | Enables revm integration for trace-based analysis | No |
cloud | Enables Railguard Cloud integration | No |
Minimum Supported Rust Version
Railguard requires Rust 1.75 or later.
Next Steps
- Types Reference — Detailed type documentation
- Configuration — Config file format
- Policy Engine — Inspection logic deep dive