Coder Social home page Coder Social logo

rszczers / flapigen-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dushistov/flapigen-rs

0.0 0.0 0.0 10.2 MB

Tool for connecting programs or libraries written in Rust with other languages

License: BSD 3-Clause "New" or "Revised" License

Rust 83.72% Java 4.86% Python 1.50% Shell 0.06% CMake 1.60% C++ 8.27%

flapigen-rs's Introduction

flapigen Build Status License Rust Documentation

Tool for connecting programs or libraries written in Rust with other languages. Foreign language api generator - flapigen. Former name rust_swig was changed to not confuse with swig. Currently implemented support for C++ and Java, but you can write support for any language of your choice. For an instruction how to integrate flapigen with your project look here.

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;
    }
}

fn f2(a: i32) -> i32 {
    a * 2
}

and you want 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);

In order to implement it flapigen suggests the following functionality, in Rust project you write (in Rust language):

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;
    fn f2(_: i32) -> i32;
});

and that's all, as a result flapigen generates JNI wrappers for Rust functions and Java code to call these JNI functions or generates C compatible wrappers in case of C++ and C++ code to call these C functions.

If you want the interface file (the file containing foreign_class! and so on) to be automatically generated for you, checkout rifgen.

Users Guide

๐Ÿ“š Read the flapigen users guide here! ๐Ÿ“š

flapigen-rs's People

Contributors

adamrzepka avatar arrtchiu avatar coltfred avatar dushistov avatar he-la avatar jasperdesutter avatar joycebabu avatar kofituo avatar peterw-lwl avatar rossdimassimo avatar rubdos avatar simlay avatar skeet70 avatar yuhanliin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.