pub struct OCamlRuntime { /* private fields */ }
Expand description
Per-thread handle to the OCaml runtime.
The first call to OCamlRuntime::init()
on the “main” thread
will perform caml_startup
and initialize the runtime. The
returned OCamlRuntimeStartupGuard
, once dropped, will
perform the OCaml runtime shutdown and release resources.
In normal use you don’t pass this handle around yourself—invoke
OCamlRuntime::with_domain_lock(...)
(or use the provided FFI
export macros) to enter the OCaml domain and get a &mut
to it.
Implementations§
Source§impl OCamlRuntime
impl OCamlRuntime
Sourcepub fn init() -> Result<OCamlRuntimeStartupGuard, String>
pub fn init() -> Result<OCamlRuntimeStartupGuard, String>
Initialize the OCaml runtime exactly once.
Returns a OCamlRuntimeStartupGuard
that will perform the
OCaml runtime shutdown and release resources once dropped.
Returns Err(String)
if called more than once.
Sourcepub fn releasing_runtime<T, F>(&mut self, f: F) -> Twhere
F: FnOnce() -> T,
pub fn releasing_runtime<T, F>(&mut self, f: F) -> Twhere
F: FnOnce() -> T,
Release the OCaml runtime lock, call f
, and re-acquire the OCaml runtime lock.
Sourcepub fn get<'tmp, T>(&'tmp self, reference: OCamlRef<'_, T>) -> OCaml<'tmp, T>
pub fn get<'tmp, T>(&'tmp self, reference: OCamlRef<'_, T>) -> OCaml<'tmp, T>
Returns the OCaml valued to which this GC tracked reference points to.
Sourcepub fn with_domain_lock<F, T>(f: F) -> Twhere
F: FnOnce(&mut Self) -> T,
pub fn with_domain_lock<F, T>(f: F) -> Twhere
F: FnOnce(&mut Self) -> T,
Run f with the OCaml lock held (enter / leave automatically).
This is a blocking call that will wait until the OCaml runtime is available.