1pub mod loader;
9pub mod registry;
10pub mod validator;
11pub mod error;
12pub mod metrics;
13
14pub use error::{Error, Result};
15pub use loader::{PatchLoader, Library};
16pub use registry::{PatchRegistry, PatchInfo, PatchRecord};
17pub use validator::{Validator, ValidationConfig};
18
19use dynpatch_interface::Version;
20use tracing::{debug, info};
21
22pub fn init() {
27 debug!("Initializing dynpatch runtime with defaults");
28 info!("dynpatch v{} initialized", env!("CARGO_PKG_VERSION"));
29 }
31
32pub struct RuntimeBuilder {
46 interface_version: Version,
47 type_hash: u64,
48}
49
50impl RuntimeBuilder {
51 pub fn new() -> Self {
52 Self {
53 interface_version: Version::new(0, 1, 0),
54 type_hash: 0,
55 }
56 }
57
58 pub fn interface_version(mut self, version: Version) -> Self {
60 self.interface_version = version;
61 self
62 }
63
64 pub fn type_hash(mut self, hash: u64) -> Self {
66 self.type_hash = hash;
67 self
68 }
69
70 pub fn init(self) {
72 info!(
73 "dynpatch runtime initialized: interface v{}, type_hash {:x}",
74 self.interface_version, self.type_hash
75 );
76 }
79}
80
81impl Default for RuntimeBuilder {
82 fn default() -> Self {
83 Self::new()
84 }
85}
86
87pub fn reload(path: &str) -> Result<()> {
92 registry::global_registry().load(path)
93}
94
95pub fn rollback() -> Result<()> {
97 registry::global_registry().rollback()
98}
99
100pub fn active_patch_info() -> Option<PatchInfo> {
102 registry::global_registry().active_patch()
103}
104
105pub fn history() -> Vec<PatchRecord> {
107 registry::global_registry().history()
108}
109
110#[cfg(test)]
111mod tests {
112 use super::*;
113
114 #[test]
115 fn test_init() {
116 init();
117 }
119}