pub mod loader;
pub mod registry;
pub mod validator;
pub mod error;
pub mod metrics;
pub use error::{Error, Result};
pub use loader::{PatchLoader, Library};
pub use registry::{PatchRegistry, PatchInfo, PatchRecord};
pub use validator::{Validator, ValidationConfig};
use dynpatch_interface::Version;
use tracing::{debug, info};
pub fn init() {
debug!("Initializing dynpatch runtime with defaults");
info!("dynpatch v{} initialized", env!("CARGO_PKG_VERSION"));
}
pub struct RuntimeBuilder {
interface_version: Version,
type_hash: u64,
}
impl RuntimeBuilder {
pub fn new() -> Self {
Self {
interface_version: Version::new(0, 1, 0),
type_hash: 0,
}
}
pub fn interface_version(mut self, version: Version) -> Self {
self.interface_version = version;
self
}
pub fn type_hash(mut self, hash: u64) -> Self {
self.type_hash = hash;
self
}
pub fn init(self) {
info!(
"dynpatch runtime initialized: interface v{}, type_hash {:x}",
self.interface_version, self.type_hash
);
}
}
impl Default for RuntimeBuilder {
fn default() -> Self {
Self::new()
}
}
pub fn reload(path: &str) -> Result<()> {
registry::global_registry().load(path)
}
pub fn rollback() -> Result<()> {
registry::global_registry().rollback()
}
pub fn active_patch_info() -> Option<PatchInfo> {
registry::global_registry().active_patch()
}
pub fn history() -> Vec<PatchRecord> {
registry::global_registry().history()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_init() {
init();
}
}