Struct jlrs::Julia [−][src]
pub struct Julia { /* fields omitted */ }
Expand description
A Julia instance. You must create it with Julia::init
or Julia::init_with_image
before you can do anything related to Julia. While this struct exists Julia is active,
dropping it causes the shutdown code to be called but this doesn’t leave Julia in a state from which it can be reinitialized.
Implementations
Initialize Julia, this method can only be called once. If it’s called a second time it will return an error. If this struct is dropped, you will need to restart your program to be able to call Julia code again.
This method is unsafe because it can race with another crate initializing Julia.
pub unsafe fn init_with_image<P: AsRef<Path>, Q: AsRef<Path>>(
julia_bindir: P,
image_path: Q
) -> JlrsResult<Self>
pub unsafe fn init_with_image<P: AsRef<Path>, Q: AsRef<Path>>(
julia_bindir: P,
image_path: Q
) -> JlrsResult<Self>
This method is similar to Julia::init
except that it loads a custom system image. A
custom image can be generated with the PackageCompiler
package for Julia. The main
advantage of using a custom image over the default one is that it allows you to avoid much
of the compilation overhead often associated with Julia.
Two arguments are required to call this method compared to Julia::init
;
julia_bindir
and image_relative_path
. The first must be the absolute path to a
directory that contains a compatible Julia binary (eg ${JULIA_DIR}/bin
), the second must
be either an absolute or a relative path to a system image.
This method will return an error if either of the two paths doesn’t exist or if Julia has already been initialized. It is unsafe because it can race with another crate initializing Julia.
Calls include
in the Main
module in Julia, which executes the file’s contents in that
module. This has the same effect as calling include
in the Julia REPL.
Example:
julia.include("Path/To/MyJuliaCode.jl").unwrap();
pub fn scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, &mut GcFrame<'base, Sync>) -> JlrsResult<T>,
pub fn scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, &mut GcFrame<'base, Sync>) -> JlrsResult<T>,
This method is a main entrypoint to interact with Julia. It takes a closure with two
arguments, a Global
and a mutable reference to a GcFrame
, and can return arbitrary
results.
Example:
julia.scope(|_global, frame| { let _i = Value::new(&mut *frame, 1u64)?; Ok(()) }).unwrap();
pub fn scope_with_slots<T, F>(&mut self, slots: usize, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, &mut GcFrame<'base, Sync>) -> JlrsResult<T>,
pub fn scope_with_slots<T, F>(&mut self, slots: usize, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, &mut GcFrame<'base, Sync>) -> JlrsResult<T>,
This method is a main entrypoint to interact with Julia. It takes a closure with two
arguments, a Global
and a mutable reference to a GcFrame
, and can return arbitrary
results. The frame will preallocate slots
slots.
Example:
julia.scope_with_slots(1, |_global, frame| { // Uses the preallocated slot let _i = Value::new(&mut *frame, 1u64)?; // Allocates a new slot, because only a single slot was preallocated let _j = Value::new(&mut *frame, 1u64)?; Ok(()) }).unwrap();
Trait Implementations
Returns true
if the GC is enabled.
Force a collection.
Insert a safepoint, a point where the garbage collector may run.
Auto Trait Implementations
impl RefUnwindSafe for Julia
impl UnwindSafe for Julia