https://github.com/taaitaaiger/jlrsreflect.jl
Generate Rust wrappers for Julia types that can be used with jlrs
https://github.com/taaitaaiger/jlrsreflect.jl
julia rust
Last synced: about 1 year ago
JSON representation
Generate Rust wrappers for Julia types that can be used with jlrs
- Host: GitHub
- URL: https://github.com/taaitaaiger/jlrsreflect.jl
- Owner: Taaitaaiger
- License: mit
- Created: 2020-07-02T18:30:51.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T00:43:37.000Z (over 3 years ago)
- Last Synced: 2025-03-24T13:11:14.043Z (about 1 year ago)
- Topics: julia, rust
- Language: Julia
- Homepage:
- Size: 197 KB
- Stars: 21
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JlrsReflect
[](https://codecov.io/gh/Taaitaaiger/JlrsReflect.jl)
This package can be used to generate jlrs-compatible Rust implementations of Julia structs (wrappers).
Wrappers can be generated for many structs, including structs with union fields, tuple fields, and type parameters. Wrappers are recursively generated for all of a type's fields, and are always generated for the most general case; any provided type parameter is erased and included in the set of structs for which wrappers are generated.
Three things that are not supported are structs with union or tuple fields that depend on a type parameter (eg `struct SomeGenericStruct{T} a::Tuple{Int32, T} end`, `SomeGenericStruct{T} a::Union{Int32, T} end`), unions used as generic parameters (eg `SomeGenericStruct{Union{A,B}}`), and structs with atomic fields. An error is thrown in the first two cases, in the final case no wrapper is generated for the struct itself but wrappers for all of its dependencies will be generated.
You can use this package by calling the `reflect` function with a `Vector` of types:
```julia
struct TypeA
# ...fields
end
struct TypeB{T}
# ...fields
end
...
wrappers = JlrsReflect.reflect([TypeA, TypeB, ...]);
# Print wrappers to standard output
println(wrappers)
# Write wrappers to file
open("julia_wrappers.rs", "w") do f
write(f, wrappers)
end
```
Wrappers for types used as fields and type parameters are automatically generated. If you want or need to rename structs or their fields you can use `renamestruct!` and `renamefields!` as follows:
```julia
wrappers = JlrsReflect.reflect([TypeA, TypeB, ...])
renamestruct!(wrappers, TypeA, "StructA")
renamefields!(wrappers, TypeB, [:fielda => "field_a", :fieldb => "field_b"])
```