Taaitaaiger / jlrs

Julia bindings for Rust
MIT License
408 stars 21 forks source link

Creating/Maping rust types to Julia #78

Open Roger-luo opened 1 year ago

Roger-luo commented 1 year ago

in PyO3, one can map a rust type using PyObjectFrom to Julia, I'm wondering if there is something similar in this package to create a Julia object?

Taaitaaiger commented 1 year ago

Currently, the only way is to generate wrappers with JlrsReflect.jl. The generated wrappers derive all necessary traits to access data of that type from Rust.

The other way around is not yet possible, but will be soon. My main focus for the next version of jlrs has been the ability to export Rust types and functions in a way similar to CxxWrap. In particular, you will be able to implement the OpaqueType or ForeignType trait and use macros to export that type and its methods to Julia. This file is an example of a library that uses this feature to expose RustFFT to Julia. I have a working Yggdrasil recipe for this library locally, but haven't committed that yet.

That feature is very much geared towards creating libraries that can be distributed as JLLs, though, not embedding.