#[repr(transparent)]pub struct Module<'scope>(_, _);
Expand description
Functionality in Julia can be accessed through its module system. You can get a handle to the
three standard modules, Main
, Base
, and Core
and access their submodules through them.
If you include your own Julia code with Julia::include
, AsyncJulia::include
, or
AsyncJulia::try_include
its contents are made available relative to Main
.
The most important methods offered by this wrapper are those that let you access submodules, functions, and other global values defined in the module. These come in two variants: one that roots the result and one that doesn’t. If you never redefine the module, it’s safe to leave named functions, constants and submodules unrooted when you use them from Rust. The same holds true for other global values that are never redefined to point at another value.
Implementations
sourceimpl<'scope> Module<'scope>
impl<'scope> Module<'scope>
sourcepub fn parent<'target, F>(self, frame: &mut F) -> JlrsResult<Module<'target>> where
F: Frame<'target>,
pub fn parent<'target, F>(self, frame: &mut F) -> JlrsResult<Module<'target>> where
F: Frame<'target>,
Returns the parent of this module.
sourcepub fn parent_ref(self) -> ModuleRef<'scope>
pub fn parent_ref(self) -> ModuleRef<'scope>
Returns the parent of this module without rooting it.
sourcepub unsafe fn extend<'global>(self, _: Global<'global>) -> Module<'global>
pub unsafe fn extend<'global>(self, _: Global<'global>) -> Module<'global>
Extend the lifetime of this module. This is safe as long as the module is never redefined.
sourcepub fn main(_: Global<'scope>) -> Self
pub fn main(_: Global<'scope>) -> Self
Returns a handle to Julia’s Main
-module. If you include your own Julia code with
Julia::include
, AsyncJulia::include
, or AsyncJulia::try_include
its contents
are made available relative to Main
.
sourcepub fn is_imported<N: TemporarySymbol>(self, sym: N) -> bool
pub fn is_imported<N: TemporarySymbol>(self, sym: N) -> bool
Returns true
if self
has imported sym
.
sourcepub fn submodule<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Module<'target>> where
N: TemporarySymbol,
F: Frame<'target>,
pub fn submodule<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Module<'target>> where
N: TemporarySymbol,
F: Frame<'target>,
Returns the submodule named name
relative to this module. You have to visit this level
by level: you can’t access Main.A.B
by calling this function with "A.B"
, but have to
access A
first and then B
.
Returns an error if the submodule doesn’t exist.
sourcepub fn submodule_ref<N>(self, name: N) -> JlrsResult<ModuleRef<'scope>> where
N: TemporarySymbol,
pub fn submodule_ref<N>(self, name: N) -> JlrsResult<ModuleRef<'scope>> where
N: TemporarySymbol,
Returns the submodule named name
relative to this module without rooting it. You have to
access this level by level: you can’t access Main.A.B
by calling this function with
"A.B"
, but have to access A
first and then B
.
Returns an error if the submodule doesn’t exist.
sourcepub fn set_global<'frame, N, F>(
self,
frame: &mut F,
name: N,
value: Value<'_, 'static>
) -> JlrsResult<JuliaResult<'frame, 'static, ValueRef<'scope, 'static>>> where
N: TemporarySymbol,
F: Frame<'frame>,
pub fn set_global<'frame, N, F>(
self,
frame: &mut F,
name: N,
value: Value<'_, 'static>
) -> JlrsResult<JuliaResult<'frame, 'static, ValueRef<'scope, 'static>>> where
N: TemporarySymbol,
F: Frame<'frame>,
Set a global value in this module. Note that if this global already exists, this can make the old value unreachable. If an excection is thrown, it’s caught, rooted and returned.
sourcepub fn set_global_unrooted<N>(
self,
name: N,
value: Value<'_, 'static>
) -> JuliaResultRef<'scope, 'static> where
N: TemporarySymbol,
pub fn set_global_unrooted<N>(
self,
name: N,
value: Value<'_, 'static>
) -> JuliaResultRef<'scope, 'static> where
N: TemporarySymbol,
Set a global value in this module. Note that if this global already exists, this can make the old value unreachable. If an exception is thrown it’s caught but not rooted and returned.
sourcepub fn set_global_unchecked<N>(
self,
name: N,
value: Value<'_, 'static>
) -> ValueRef<'scope, 'static> where
N: TemporarySymbol,
pub fn set_global_unchecked<N>(
self,
name: N,
value: Value<'_, 'static>
) -> ValueRef<'scope, 'static> where
N: TemporarySymbol,
Set a global value in this module. Note that if this global already exists, this can make the old value unreachable. If an exception is thrown the process aborts.
sourcepub fn set_const<'frame, N, F>(
self,
frame: &mut F,
name: N,
value: Value<'_, 'static>
) -> JlrsResult<JuliaResult<'frame, 'static, ValueRef<'scope, 'static>>> where
N: TemporarySymbol,
F: Frame<'frame>,
pub fn set_const<'frame, N, F>(
self,
frame: &mut F,
name: N,
value: Value<'_, 'static>
) -> JlrsResult<JuliaResult<'frame, 'static, ValueRef<'scope, 'static>>> where
N: TemporarySymbol,
F: Frame<'frame>,
Set a constant in this module. If Julia throws an exception it’s caught and rooted in the
current frame, if the exception can’t be rooted a JlrsError::AllocError
is returned. If
no exception is thrown an unrooted reference to the constant is returned.
sourcepub fn set_const_unrooted<N>(
self,
name: N,
value: Value<'_, 'static>
) -> JuliaResultRef<'scope, 'static> where
N: TemporarySymbol,
pub fn set_const_unrooted<N>(
self,
name: N,
value: Value<'_, 'static>
) -> JuliaResultRef<'scope, 'static> where
N: TemporarySymbol,
Set a constant in this module. If Julia throws an exception it’s caught. Otherwise an unrooted reference to the constant is returned.
sourcepub fn set_const_unchecked<N>(
self,
name: N,
value: Value<'_, 'static>
) -> ValueRef<'scope, 'static> where
N: TemporarySymbol,
pub fn set_const_unchecked<N>(
self,
name: N,
value: Value<'_, 'static>
) -> ValueRef<'scope, 'static> where
N: TemporarySymbol,
Set a constant in this module. If the constant already exists the process aborts, otherwise an unrooted reference to the constant is returned.
sourcepub fn global<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Value<'target, 'static>> where
N: TemporarySymbol,
F: Frame<'target>,
pub fn global<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Value<'target, 'static>> where
N: TemporarySymbol,
F: Frame<'target>,
Returns the global named name
in this module.
Returns an error if the global doesn’t exist.
sourcepub fn global_ref<N>(self, name: N) -> JlrsResult<ValueRef<'scope, 'static>> where
N: TemporarySymbol,
pub fn global_ref<N>(self, name: N) -> JlrsResult<ValueRef<'scope, 'static>> where
N: TemporarySymbol,
Returns the global named name
in this module without rooting it.
Returns an error if the global doesn’t exist.
sourcepub fn leaked_global<N>(self, name: N) -> JlrsResult<LeakedValue> where
N: TemporarySymbol,
pub fn leaked_global<N>(self, name: N) -> JlrsResult<LeakedValue> where
N: TemporarySymbol,
Returns the global named name
in this module as a LeakedValue
.
Returns an error if the global doesn’t exist.
sourcepub fn function<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Function<'target, 'static>> where
N: TemporarySymbol,
F: Frame<'target>,
pub fn function<'target, N, F>(
self,
frame: &mut F,
name: N
) -> JlrsResult<Function<'target, 'static>> where
N: TemporarySymbol,
F: Frame<'target>,
Returns the function named name
in this module.
Returns an error if the function doesn’t exist or if it’s not a subtype of Function
.
sourcepub fn function_ref<N>(
self,
name: N
) -> JlrsResult<FunctionRef<'scope, 'static>> where
N: TemporarySymbol,
pub fn function_ref<N>(
self,
name: N
) -> JlrsResult<FunctionRef<'scope, 'static>> where
N: TemporarySymbol,
Returns the function named name
in this module without rooting it.
Returns an error if the function doesn’t exist or if it’s not a subtype of Function
.
sourcepub fn as_leaked(self) -> LeakedValue
pub fn as_leaked(self) -> LeakedValue
Convert self
to a LeakedValue
.
sourcepub fn require<'target, 'current, S, F, N>(
self,
scope: S,
module: N
) -> JlrsResult<S::JuliaResult> where
S: Scope<'target, 'current, 'static, F>,
F: Frame<'current>,
N: TemporarySymbol,
pub fn require<'target, 'current, S, F, N>(
self,
scope: S,
module: N
) -> JlrsResult<S::JuliaResult> where
S: Scope<'target, 'current, 'static, F>,
F: Frame<'current>,
N: TemporarySymbol,
Load a module by calling Base.require
and return this module if it has been loaded
successfully. This method can be used to load parts of the standard library like
LinearAlgebra
. This requires one slot on the GC stack. Note that the loaded module is
not made available in the module used to call this method, you can use
Module::set_global
to do so.
Note that when you want to call using Submodule
in the Main
module, you can do so by
evaluating the using-statement with Value::eval_string
.
sourcepub fn require_ref<S>(
self,
global: Global<'scope>,
module: S
) -> ModuleRef<'scope> where
S: TemporarySymbol,
pub fn require_ref<S>(
self,
global: Global<'scope>,
module: S
) -> ModuleRef<'scope> where
S: TemporarySymbol,
Load a module by calling Base.require
and return this module if it has been loaded
successfully. This method can be used to load parts of the standard library like
LinearAlgebra
. Unlike Module::require
, this method will panic if the module cannot
be loaded. Note that the loaded module is not made available in the module used to call
this method, you can use Module::set_global
to do so.
Note that when you want to call using Submodule
in the Main
module, you can do so by
evaluating the using-statement with Value::eval_string
.
Trait Implementations
sourceimpl<'target> ValidLayout for Module<'target>
impl<'target> ValidLayout for Module<'target>
sourcefn valid_layout(v: Value<'_, '_>) -> bool
fn valid_layout(v: Value<'_, '_>) -> bool
Check if the layout of the implementor is compatible with the layout of ty
. This
argument is a Value
to account for the fact that a field type can be a Union
,
UnionAll
or Union{}
. Read more
impl<'scope> Copy for Module<'scope>
impl<'target> Typecheck for Module<'target>
Auto Trait Implementations
impl<'scope> RefUnwindSafe for Module<'scope>
impl<'scope> !Send for Module<'scope>
impl<'scope> !Sync for Module<'scope>
impl<'scope> Unpin for Module<'scope>
impl<'scope> UnwindSafe for Module<'scope>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<'scope, 'data, W> Wrapper<'scope, 'data> for W where
W: Wrapper<'scope, 'data>,
impl<'scope, 'data, W> Wrapper<'scope, 'data> for W where
W: Wrapper<'scope, 'data>,
sourcefn display_string(self) -> JlrsResult<String>
fn display_string(self) -> JlrsResult<String>
Convert the wrapper to its display string, i.e. the string that is shown when calling
Base.show
. Read more
sourcefn error_string(self) -> JlrsResult<String>
fn error_string(self) -> JlrsResult<String>
Convert the wrapper to its error string, i.e. the string that is shown when calling
Base.showerror
. This string can contain ANSI color codes if this is enabled by calling
Julia::error_color
, AsyncJulia::error_color
, or AsyncJulia::try_error_color
, . Read more