Expand description
§dynpatch
Safe live code reloading for Rust applications.
dynpatch enables runtime hot-patching of Rust code with strong safety guarantees,
transactional semantics, and automatic rollback on failure.
§Features
- Runtime hot patching: Update code without restarting
- Safety first: Strong ABI/type compatibility checks
- Transactional: All-or-nothing activation with automatic rollback
- State continuity: Optional state migration between versions
- Minimal overhead: Lock-free implementation swapping
- Developer friendly: Macros, CLI, file watching, and introspection
§Quick Start
§Basic Usage
ⓘ
use dynpatch::prelude::*;
// Initialize the runtime
init();
// Load a patch
reload("path/to/patch.so")?;
// Check active patch
if let Some(info) = active_patch_info() {
println!("Active: {} v{}", info.name, info.version);
}
// Rollback if needed
rollback()?;§Advanced Configuration
ⓘ
use dynpatch::prelude::*;
use dynpatch_interface::Version;
// Configure the runtime with specific requirements
RuntimeBuilder::new()
.interface_version(Version::new(1, 0, 0))
.type_hash(0x1234567890abcdef)
.init();§Mark code as patchable
ⓘ
use dynpatch::prelude::*;
#[patch_trait]
pub trait Handler {
fn handle(&self, request: Request) -> Response;
}
#[patchable]
fn process_data(data: &str) -> String {
data.to_uppercase()
}§Hot-reload configuration
ⓘ
use dynpatch::config::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize)]
struct AppConfig {
max_connections: usize,
timeout_ms: u64,
}
impl HotConfig for AppConfig {}
fn main() {
let watcher = watch::<AppConfig, _>("config.toml").unwrap();
loop {
let config = watcher.get();
println!("Max connections: {}", config.max_connections);
std::thread::sleep(std::time::Duration::from_secs(1));
}
}§Architecture
dynpatch consists of several components:
- dynpatch-core: Runtime engine for loading and managing patches
- dynpatch-macro: Procedural macros for marking patchable code
- dynpatch-interface: Shared types for host-patch communication
- dynpatch-watcher: File watching and config reloading
- dynpatch-cli: Command-line tool for building and managing patches
§Safety Guarantees
- ABI validation: Type layout and signature checking before activation
- Version compatibility: Semantic versioning with compatibility rules
- Transactional swaps: Atomic activation with automatic rollback on failure
- Thread safety: Lock-free RCU-like publication using
arc-swap - Panic safety: Catch initialization panics and rollback
§Optional Features
watcher(default) - File watching and config reloadingabi_stable- Enhanced ABI checks usingabi_stablecratemetrics- Performance and operation metricssigning- Cryptographic patch signature verificationsandbox- Process isolation for untrusted patchesjson,yaml,toml- Config format support
Modules§
Structs§
- Patch
Info - Information about a loaded patch
- Patch
Metadata - Metadata about a patch
- Patch
Record - Historical record of a patch load/unload
- Runtime
Builder - Builder for configuring the dynpatch runtime
- Type
Layout - Information about type layout for ABI validation
- Version
- Version information for patches
Enums§
- Patch
Error - Errors that can occur during patch operations
Traits§
- Patch
Interface - Trait for patchable interfaces
- State
Migration - State migration trait for carrying state across patch versions
Functions§
- active_
patch_ info - Get information about the currently active patch
- compute_
type_ hash - Compute a deterministic hash of a type’s name for compatibility checking
- history
- Get the history of all loaded patches
- init
- Initialize the dynpatch runtime with default settings
- reload
- Reload a patch from the specified path
- rollback
- Rollback to the previous patch
- watch
- Watch a file and call a callback on changes
Attribute Macros§
- patch_
entry - Mark patch entry point with initialization
- patch_
impl - Mark a struct as a patch implementation
- patch_
trait - Mark a trait as a patchable interface
- patchable
- Mark a function as patchable
Derive Macros§
- HotConfig
- Derive macro for hot-reloadable configuration