| Crates.io | dynpatch |
| lib.rs | dynpatch |
| version | 0.1.0 |
| created_at | 2025-10-15 10:51:00.443721+00 |
| updated_at | 2025-10-15 10:51:00.443721+00 |
| description | Safe live code reloading for Rust - hot patch functions, services, and configs at runtime |
| homepage | |
| repository | https://gitlab.com/TIVisionOSS/crates/dynpatch |
| max_upload_size | |
| id | 1884179 |
| size | 42,039 |
Safe live code reloading for Rust. Hot-patch functions, services, and configurations at runtime with type/ABI validation, transactional swaps, and automatic rollback.
Add dynpatch to your Cargo.toml:
[dependencies]
dynpatch = "0.1"
use dynpatch::prelude::*;
#[patch_trait]
pub trait Handler {
fn handle(&self, request: &str) -> String;
}
#[patchable]
fn process_data(data: &str) -> String {
data.to_uppercase()
}
use dynpatch::prelude::*;
fn main() {
// Initialize the runtime
init();
// Your application loop
loop {
// ... application logic ...
// Load a patch when ready
if let Ok(_) = reload("path/to/patch.so") {
println!("Patch applied!");
}
}
}
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();
// Config updates automatically when the file changes
let config = watcher.get();
println!("Max connections: {}", config.max_connections);
}
#[patchable] and #[patch_trait] macros.so/.dylib/.dll)Install the CLI for building and managing patches:
cargo install dynpatch-cli
Commands:
dynpatch build - Compile a patch from sourcedynpatch apply - Apply a patch to a running processdynpatch rollback - Revert to previous versiondynpatch inspect - Show patch status and historydynpatch watch - Auto-apply patches from a directorywatcher (default) - File watching and config reloadingabi_stable - Enhanced ABI checksmetrics - Performance metricssigning - Cryptographic signature verificationsandbox - Process isolation for untrusted patchesjson, yaml, toml - Config format supportRust 1.70.0 or later.
.so).dylib).dll)See the examples/ directory for complete working examples:
http_handler - Hot-patching an HTTP request handlerconfig_reload - Live config reloading with file watchingservice_swap - Trait-based service swappingContributions are welcome! See CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
https://gitlab.com/TIVisionOSS/crates/dynpatch
Eshan Roy m.eshanized@gmail.com