j4rs,一个在 Rust 中调用 Java 代码的 Cratej4rs 是 Rust 的一个库,提供了一些从 Rust 端调用 Java 函数的一些工具。use j4rs::prelude::*;
use j4rs_derive::*;
#[call_from_java("io.github.astonbitecode.j4rs.example.RustSimpleFunctionCall.fnnoargs")]
fn my_function_with_no_args() {
println!("Hello from the Rust world!");
}
package io.github.astonbitecode.j4rs.example;
public class RustSimpleFunctionCall {
private static native void fnnoargs();
static {
System.loadLibrary("rustlib");
}
public void doCallNoArgs() {
fnnoargs();
}
}
#![feature(unboxed_closures, fn_traits, type_alias_impl_trait, impl_trait_in_bindings)]
use functionate::functionate;
use std::ops::Fn;
#[allow(non_upper_case_globals)]
static foo: impl Fn() -> &'static str + Fn(i32) -> i32 = {
struct Foo;
#[functionate]
impl Foo {
fn a(&self) -> &'static str { "bar" }
fn b(&self, x: i32) -> i32 { x * 2 }
}
Foo
};
fn main() {
println!("{}", foo());
println!("{}", foo(5));
}
doc:https://docs.rs/bin_packer_3d/1.0.0/bin_packer_3d/
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。