pub struct CCall { /* private fields */ }
Expand description
Use Julia from a Rust function called through ccall
.
When you call Rust from Julia through ccall
, Julia has already been initialized and trying to
initialize it again would cause a crash. In order to still be able to call Julia from Rust
and to borrow arrays (if you pass them as Array
rather than Ptr{Array}
), you’ll need to
create a scope first. You can use this struct to do so. It must never be used outside
functions called through ccall
, and only once for each ccall
ed function.
If you only need to use a frame to borrow array data, you can use CCall::null_scope
.
Unlike the runtimes, CCall
postpones the allocation of the stack that is used for managing
the GC until a GcFrame
is created. If a null scope is created, this stack isn’t allocated at
all.
Implementations
sourceimpl CCall
impl CCall
sourcepub unsafe fn new() -> Self
pub unsafe fn new() -> Self
Create a new CCall
. The stack is not allocated until a GcFrame
is created.
Safety: This function must never be called outside a function called through ccall
from
Julia and must only be called once during that call.
sourcepub unsafe fn uv_async_send(handle: *mut c_void) -> bool
pub unsafe fn uv_async_send(handle: *mut c_void) -> bool
Wake the task associated with handle
.
The handle must be the handle
field of a Base.AsyncCondition
in Julia. This can be
used to call a long-running Rust function from Julia with ccall
in another thread and
wait for it to complete in Julia without blocking, an example is available in the
repository: ccall_with_threads
.
This method is only available if the uv
feature is enabled.
Safety: the handle must be acquired from an AsyncCondition
.
sourcepub fn scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, GcFrame<'base, Sync>) -> JlrsResult<T>,
pub fn scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, GcFrame<'base, Sync>) -> JlrsResult<T>,
Create a GcFrame
, call the given closure, and return its result.
sourcepub fn scope_with_capacity<T, F>(
&mut self,
capacity: usize,
func: F
) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, GcFrame<'base, Sync>) -> JlrsResult<T>,
pub fn scope_with_capacity<T, F>(
&mut self,
capacity: usize,
func: F
) -> JlrsResult<T> where
for<'base> F: FnOnce(Global<'base>, GcFrame<'base, Sync>) -> JlrsResult<T>,
Create a GcFrame
with capacity for at least capacity
roots, call the given closure
and return its result.
sourcepub fn null_scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(NullFrame<'base>) -> JlrsResult<T>,
pub fn null_scope<T, F>(&mut self, func: F) -> JlrsResult<T> where
for<'base> F: FnOnce(NullFrame<'base>) -> JlrsResult<T>,
Auto Trait Implementations
impl !RefUnwindSafe for CCall
impl !Send for CCall
impl !Sync for CCall
impl Unpin for CCall
impl UnwindSafe for CCall
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