Coder Social home page Coder Social logo

java-rust-example's Introduction

Java/Rust Example

An example project showing how to call into Rust code from Java.

OSX Linux Windows
OSX Build Status Linux Build Status Windows Build status

Requirements

  • Java 7+
  • Rust (tested with 1.0, nightly)

Contents

So far, the project contains

  • Rust code and Java code
  • A Java interface to the Rust code, using JNA
  • A script to build the Rust code into a library and put it on the classpath where JNA can find it
  • Examples of passing strings, structs, and callback functions between Java and Rust

Getting Started

The best place to start looking at the examples is in the test code (GreetingsTest.java). The test contains lots of executable examples of calling into Rust code from Java. From the test, you can navigate to the Java code and the Rust code. The implementation is heavily commented to explain it.

So far, it contains examples of the following (click the links to see!):

Building and Running the Tests

To build the project, and run the tests, use Maven. This will build a jar containing the Rust code and the Java code. This assumes you have Rust installed, and on the path.

$ mvn package

You can then run the jar that is produced to see the integration work.

$ java -jar target/greeter.jar John
Hello from Rust, John

Platform Support

This project is tested on OSX, Ubuntu, and Windows. It should also work on any 32 bit or 64 bit Gnu/Linux system.

Limitations

Some of the examples leak memory. Any memory that is allocated in Rust needs to be freed manually because it's not managed by JNA. Some examples pass objects back into Rust to be dropped for this reason, but we don't clean up everything properly (strings, for example). This is almost certainly not a limitation of Rust, but a limitation of my current understanding of Rust.

License

Java/Rust Example Copyright (C) 2015 drrb

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

java-rust-example's People

Contributors

drrb avatar

Watchers

 avatar James Cloos 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.