{"id":13437854,"url":"https://github.com/drrb/java-rust-example","last_synced_at":"2025-12-16T13:56:50.056Z","repository":{"id":11247968,"uuid":"13645881","full_name":"drrb/java-rust-example","owner":"drrb","description":"Embedding Rust in Java","archived":false,"fork":false,"pushed_at":"2022-04-24T04:57:49.000Z","size":103,"stargazers_count":340,"open_issues_count":2,"forks_count":38,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-19T18:38:33.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drrb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-17T10:29:54.000Z","updated_at":"2025-02-16T06:02:31.000Z","dependencies_parsed_at":"2022-08-24T19:30:19.533Z","dependency_job_id":null,"html_url":"https://github.com/drrb/java-rust-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drrb/java-rust-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drrb%2Fjava-rust-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drrb%2Fjava-rust-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drrb%2Fjava-rust-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drrb%2Fjava-rust-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drrb","download_url":"https://codeload.github.com/drrb/java-rust-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drrb%2Fjava-rust-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27765942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-16T02:00:10.477Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:00.715Z","updated_at":"2025-12-16T13:56:50.023Z","avatar_url":"https://github.com/drrb.png","language":"Java","readme":"# Java/Rust Example\n\nAn example project showing how to call into Rust code from Java.\n\n| OSX | Linux | Windows |\n| --- | ----- | ------- |\n| ![OSX Build Status](https://img.shields.io/badge/build-passing%20on%20my%20laptop-brightgreen.svg) | [![Linux Build Status](https://travis-ci.org/drrb/java-rust-example.svg?branch=master)](https://travis-ci.org/drrb/java-rust-example) | [![Windows Build status](https://ci.appveyor.com/api/projects/status/4yygb3925k7p87de/branch/master?svg=true)](https://ci.appveyor.com/project/drrb/java-rust-example/branch/master) |\n\n## Requirements\n\n- Java 7+\n- Rust (tested with 1.0, nightly)\n\n## Contents\n\nSo far, the project contains\n- Rust code and Java code\n- A Java interface to the Rust code, using [JNA](https://github.com/twall/jna)\n- A script to build the Rust code into a library and put it on the classpath where JNA can find it\n- Examples of passing strings, structs, and callback functions between Java and Rust\n\n## Getting Started\n\nThe best place to start looking at the examples is in the test code\n([GreetingsTest.java](src/test/java/com/github/drrb/javarust/GreetingsTest.java)).\nThe test contains lots of executable examples of calling into Rust code from\nJava.  From the test, you can navigate to the [Java code](src/main/java/com/github/drrb/javarust/Greetings.java)\nand the [Rust code](src/main/rust/com/github/drrb/javarust/lib/greetings.rs). The\nimplementation is heavily commented to explain it.\n\nSo far, it contains examples of the following (click the links to see!):\n- *[Arguments](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L45)*: passing simple arguments from Java to Rust ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L44) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L81))\n- *[Return values](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L50)*: returning simple values from Rust to Java ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L49) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L91))\n- *[Struct arguments](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L56)*: passing structs to Rust from Java ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L54) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L100))\n- *[Returning structs (2 examples)](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L65)*: returning structs from Rust by value and by reference ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L71) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L109))\n- *[Callbacks (3 examples)](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L80)*: passing callbacks to Rust that get called from the Rust code ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L84) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L129))\n- *[Freeing memory](src/test/java/com/github/drrb/javarust/GreetingsTest.java#L67)*: freeing memory allocated in Rust ([Java side](src/main/java/com/github/drrb/javarust/Greetings.java#L114) / [Rust side](src/main/rust/com/github/drrb/javarust/lib/greetings.rs#L171))\n\n## Building and Running the Tests\n\nTo build the project, and run the tests, use Maven. This will build a jar\ncontaining the Rust code and the Java code. This assumes you have Rust\ninstalled, and on the path.\n\n```\n$ mvn package\n```\n\nYou can then run the jar that is produced to see the integration work.\n\n```\n$ java -jar target/greeter.jar John\nHello from Rust, John\n```\n\n## Platform Support\n\nThis project is tested on OSX, Ubuntu, and Windows. It should also work on any 32 bit or 64 bit Gnu/Linux system.\n\n## Limitations\n\nSome 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.\n\n## License\n\nJava/Rust Example\nCopyright (C) 2015 drrb\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","funding_links":[],"categories":["Development tools","开发工具 Development tools","开发工具"],"sub_categories":["FFI","FFI FFI","示例 FFI"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrrb%2Fjava-rust-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrrb%2Fjava-rust-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrrb%2Fjava-rust-example/lists"}