Translator
Translator is a rust procedural macro which translates rust structs into other languages for exposure over a rust FFI (or however else you want to use them). Structs that are not [repr(C)]
are ignored. The structs are translated into:
- Python
- C++
- C#
This macro isn't a magic bullet, but it will (hopefully) greatly reduce the cost of creating Rust libraries for use with other languages
Use
Input
Say you want to translate the following structs:
You would have to add the Translator macro, and the Translator
to the derivations. You would also have to add the 'magic struct' to the end of the struct declarations. It would look like this:
extern crate translator;
When you compile, in the 'target' folder a new folder will be created named 'TranslateOutput' with 3 files (one for each language) with the following contents:
c++
typedef struct SomeStructTag SomeStruct;
typedef struct BazTag Baz;
Python
=
=
C#
[StructLayout(LayoutKind.Sequential)]
public struct SomeStruct
{
public int foo;
public Baz bar;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public byte[] foobar;
}
[StructLayout(LayoutKind.Sequential)]
public struct Baz
{
public float bob;
}
Mastodon