Open Taaitaaiger opened 1 year ago
Looking forward to this, I'm coming from Julia and now learning Rust, and a step-by-step on how to use this for newbies like me would really help a lot indeed. I'm planning to use jlrs
to embed Julia within Rust applications. I will try to learn this library (though might take sometime), and hoping to contribute to the documentations.
The only information that's currently available is contained within the docs. It's hard to provide a step-by-step tutorial that progressively explains how to use jlrs that way, a website and a tutorial is needed.
Summary of plans:
Introduction
The first few tutorials should focus on introducing important concepts in jlrs. I think it's best to start with embedding Rust using the sync runtime because that involves the least amount of prerequisites, and using the same structure as the Embedding Julia doc does.
Sync runtime
StackFrame
is necessary to make Julia aware of data that is in use from RustValue::eval("println(sqrt(2)")
Primitive data
Value
u8
andf64
can be converted to Julia withValue::new
, and that they can be unboxed withValue::unbox
to convert them to RustModules
Functions
Call
trait+
function and call it+
with incompatible argumentsnamed_tuple
andWithKeywords
Memory management
Value
has ascope
lifetime that ensures it can't be returned from the scope that roots itExtendedTarget
ExtendedTarget
Arrays I
Array
, explain that it doesn't express the element type or rank at a type levelArray
can be created from aVec
as long as the element type of theVec
implementsIntoJulia
Array
can be created from a slice as long as the element type of the slice implementsIntoJulia
, introduce the'data
lifetimeAsync runtime
After the introductory material, I think it's best to introduce async runtime before diving into more complex topics.
CallAsync
Data
These tutorials dive deeper into topics like Julia types and the layouts of their instances. This information is useful if you want to access or mutate the content of Julia data directly from Rust.
Types and layouts
DataType
,UnionAll
,Union
,TypeName
, andTypeVar
.DataType::instantiate
Values
Value
.Value
, introduce write barrierFieldAccessor
Arrays II
TypedArray
jlrs-ndarray
featureOther types
internal-types
feature is enabledJlrs.Reflect
JlrsReflect
CCallArg
andCCallReturn
CCall
The final set of tutorials are about calling Rust from Julia, they should focus on the
julia_module
macro and the functionality that can be exposed to Julia with it.CCall
ccall
interfaceextern "C"
functions defined in Rustcdylib
to create a library that can be loaded by JuliaCCall
type, explain that it's essentially a sync runtimejulia_module
julia_module
macro and explain what can be exported with itCCallArg
andCCallReturn
traits are used to generate the function and ccall argument and return typesRustResult
type, explain why functions called throughccall
should never throw an uncaught exceptionConstants and globals
static
andconst
global data that implementsIntoJulia
can be exported as either a module constant or globalFreestanding functions, opaque types, and their methods
unsafe extern "C"
functions can be exportedTypedValue
RustResult
from an exported functionOpaqueType
trait, explain that it can be used to expose Rust data to Juliaunsafe extern "C"
functions&self
or&mut self
Foreign types and their methods
ForeignType
trait, explain its similarities to and differences fromOpaqueType
Async function calls
AsyncCCall
traitJLL packages