Skip to main content

harn_vm/
persistent_state.rs

1//! Explicit persistent-state registration for isolated VM executions.
2
3use std::path::Path;
4
5use crate::Vm;
6
7/// A caller-owned persistent-state root that bypasses ambient runtime paths.
8#[derive(Clone, Copy, Debug)]
9pub struct PersistentStateRoot<'a>(&'a Path);
10
11impl<'a> PersistentStateRoot<'a> {
12    #[must_use]
13    pub fn new(path: &'a Path) -> Self {
14        Self(path)
15    }
16
17    fn as_path(self) -> &'a Path {
18        self.0
19    }
20}
21
22/// Register store, metadata, and checkpoint builtins at an exact state root.
23///
24/// Unlike the individual runtime registrars, this function does not consult
25/// `HARN_STATE_DIR`. Embedders use it when concurrent executions require
26/// hermetic state without mutating process-global environment variables.
27pub fn register_persistent_state_builtins_at_root(
28    vm: &mut Vm,
29    base_dir: &Path,
30    state_root: PersistentStateRoot<'_>,
31    pipeline_name: &str,
32) {
33    let state_root = state_root.as_path();
34    crate::store::register_store_builtins_at_state_root(vm, state_root);
35    crate::metadata::register_metadata_builtins_at_state_root(vm, base_dir, state_root);
36    crate::checkpoint::register_checkpoint_builtins_at_state_root(vm, state_root, pipeline_name);
37}