1 unstable release
Uses new Rust 2024
| new 0.1.0 | Mar 14, 2026 |
|---|
#55 in #jvm
83KB
1.5K
SLoC
Proc-macro implementation for inline_java.
Provides three proc macros for embedding Java in Rust:
| Macro | When it runs |
|---|---|
java! |
program runtime |
java_fn! |
program runtime |
ct_java! |
compile time |
All macros require the user to write a static <T> run(...) method
where T is one of: byte, short, int, long, float, double,
boolean, char, String, T[], List<T>, or Optional<T> —
including arbitrarily nested types like List<List<Integer>>,
Optional<List<String>>, Optional<List<Optional<Integer[]>>>, etc.
Wire format (Java → Rust, stdout)
The macro generates a main() that binary-serialises run()'s return
value to stdout via DataOutputStream (raw UTF-8 for top-level String
scalars).
Encoding per type:
Boxed(String)at top level: raw UTF-8 (no length prefix)Boxed(String)inside a container: 4-byte BE length + UTF-8 bytesPrimitive/Boxed(non-String): fixed-width big-endian bytes viaDataOutputStreamArray(T)/List(T): 4-byte BE count + N × encode(T)Optional(T): 1-byte tag (0=absent, 1=present) + encode(T) if present
Wire format (Rust → Java, stdin)
Parameters declared in run(...) are serialised by Rust and piped to the
child process's stdin. Java reads them with DataInputStream.
Options
All three macros accept zero or more key = "value" pairs before the Java body,
comma-separated. Recognised keys:
javac = "<args>"— extra arguments passed verbatim tojavac(shell-quoted; single/double quotes respected).java = "<args>"— extra arguments passed verbatim tojava(shell-quoted; single/double quotes respected).
inline_java_macros
Support crate for inline_java — not intended for direct use.
Please refer to the main crate for documentation and usage examples.
Dependencies
~2–14MB
~166K SLoC