Skip to main content

ct_java

Macro ct_java 

Source
ct_java!() { /* proc-macro */ }
Expand description

Re-export the proc macros so users only need to depend on this crate. Run Java at compile time and splice its return value as a Rust literal.

Accepts optional javac = "..." and java = "..." key-value pairs before the Java body. The user provides a static <T> run() method; its binary-serialised return value is decoded and emitted as a Rust literal at the call site (42, 3.14, true, 'x', "hello", [1, 2, 3], …).

Java compilation/runtime errors become Rust compile_error! diagnostics.

§Examples

use inline_java::ct_java;

// Numeric constant computed at compile time
const PI_APPROX: f64 = ct_java! {
    static double run() {
        return Math.PI;
    }
};

// String constant
const GREETING: &str = ct_java! {
    static String run() {
        return "Hello, World!";
    }
};

// Array constant
const PRIMES: [i32; 5] = ct_java! {
    static int[] run() {
        return new int[]{2, 3, 5, 7, 11};
    }
};