pub struct VM { /* private fields */ }Expand description
A handle to the piecrust virtual machine.
It is instantiated using new or ephemeral, and can be used to spawn
multiple Sessions using session.
These sessions are synchronized with the help of a sync loop. Deletions
and squashes are assured to not delete any commits used as a base for
sessions until these are dropped. A handle to this loop is available at
sync_thread.
Users are encouraged to instantiate a VM once during the lifetime of their
program and spawn sessions as needed.
Implementations§
source§impl VM
impl VM
sourcepub fn new<P: AsRef<Path>>(root_dir: P) -> Result<Self, Error>
pub fn new<P: AsRef<Path>>(root_dir: P) -> Result<Self, Error>
Creates a new VM, reading the given directory for existing commits
and bytecode.
The directory will be used to save any future session commits made by
this VM instance.
Errors
If the directory contains unparseable or inconsistent data.
sourcepub fn ephemeral() -> Result<Self, Error>
pub fn ephemeral() -> Result<Self, Error>
Creates a new VM using a new temporary directory.
Any session commits made by this machine should be considered discarded
once this VM instance drops.
Errors
If creating a temporary directory fails.
sourcepub fn register_host_query<Q, S>(&mut self, name: S, query: Q)where
Q: 'static + HostQuery,
S: Into<Cow<'static, str>>,
pub fn register_host_query<Q, S>(&mut self, name: S, query: Q)where Q: 'static + HostQuery, S: Into<Cow<'static, str>>,
Registers a host query with the given name.
The query will be available to any session spawned after this was called.
sourcepub fn squash_commit(&self, root: [u8; 32]) -> Result<(), Error>
pub fn squash_commit(&self, root: [u8; 32]) -> Result<(), Error>
Remove the diff files from a commit by applying them to the base memories, and writing them back to disk.
Errors
If this function fails, it may be due to any number of reasons:
remove_filemay failwritemay fail
Failing may result in a corrupted commit, and the user is encouraged to
call delete_commit.
sourcepub fn delete_commit(&self, root: [u8; 32]) -> Result<(), Error>
pub fn delete_commit(&self, root: [u8; 32]) -> Result<(), Error>
Deletes the given commit from disk.
sourcepub fn sync_thread(&self) -> &Thread
pub fn sync_thread(&self) -> &Thread
Returns a reference to the synchronization thread.