#jni #swig #java #cpp #api-bindings

rifgen

ffi Interface file generator. Use with flapigen

10 releases

0.1.61 Oct 25, 2022
0.1.51 Feb 23, 2022
0.1.7 Jun 8, 2023
0.1.6 Oct 25, 2022
0.1.4 Oct 6, 2021

#77 in FFI

Download history 81/week @ 2024-07-20 232/week @ 2024-07-27 100/week @ 2024-08-03 82/week @ 2024-08-10 46/week @ 2024-08-17 51/week @ 2024-08-24 42/week @ 2024-08-31 42/week @ 2024-09-07 62/week @ 2024-09-14 109/week @ 2024-09-21 86/week @ 2024-09-28 153/week @ 2024-10-05 121/week @ 2024-10-12 170/week @ 2024-10-19 80/week @ 2024-10-26 185/week @ 2024-11-02

575 downloads per month

MIT license

58KB
875 lines

rifgen

Rust doc Rust Documentation donate

Program for translating libraries written in Rust to interface files. It works with flapigen. For instructions on how to integrate with your project, click here. This crate was initially rust_interface_file_generator

Suppose you have the following Rust code:

struct Foo {
    data: i32
}

impl Foo {
    fn new(val: i32) -> Foo {
        Foo { data: val }
    }

    fn f(&self, a: i32, b: i32) -> i32 {
        self.data + a + b
    }

    fn set_field(&mut self, v: i32) {
        self.data = v;
    }
}

Using flapigen, you'd have to write an interface file similar to

foreign_class!(class Foo {
    self_type Foo;
    constructor Foo::new(_: i32) -> Foo;
    fn Foo::set_field(&mut self, _: i32);
    fn Foo::f(&self, _: i32, _: i32) -> i32;
});

in order to write in Java something like this:

Foo foo=new Foo(5);
        int res=foo.f(1,2);
        assert res==8;

or in C++ something like this:

Foo foo(5);
int res = foo.f(1, 2);
assert(res == 8);

This module generates the interface file, so you can focus more time on your code

Other Features:

✅ Fast and easy to use

✅ Specify style of the resulting code i.e. Whether CamelCase or snake_case

✅ Works, with structs, enums, trait

✅ You don't have to worry about the "order" in which code in the interface has to be

Users Guide

Read the rifgen users guide here!

View on crates.io

Contact Me

If you'd like to contact me to help with any project whatsoever, you can reach me on Upwork

Dependencies

~1.5MB
~40K SLoC