Skip to main content

Crate prebindgen_jni

Crate prebindgen_jni 

Source
Expand description

JNI / Kotlin language adapter — the JniGenBuilder back-end.

Sibling of the C adapter (now the separate prebindgen-c crate): it implements the language-agnostic prebindgen_registry::Prebindgen trait to turn a flat #[prebindgen] library into a Rust file of JNI extern "C" wrappers plus a fan-out of generated Kotlin sources.

Pipeline:

  1. prebindgen_registry::Registry::builder describes a binding over a model built from (syn::Item, SourceLocation) (typically source.items_all()).
  2. Registry::write_rust resolves every required type via a configured JniGenBuilder and writes the generated Rust bindings file.
  3. JniGenBuilder::write_kotlin walks the resolved registry to emit the secondary Kotlin artifacts (typed-handle classes, data/enum classes, exception classes, the centralized JNINative holder).

§Fixed-width unsigned integers

JniGenBuilder exposes Rust’s fixed-width unsigned scalars without narrowing their domain at the Kotlin boundary:

RustKotlin surfaceJNI wire
u8Intjint
u16Intjint
u32Longjlong
u64ULongjlong / Long bit pattern

Inputs for u8, u16, and u32 are range-checked and report a JniBindingError through the generated binding-error handler. u64 uses Kotlin’s bit-preserving ULong.toLong() / Long.toULong() bridge. These mappings compose through nullable/result outputs, generated data classes, callbacks, const getters, and supported output collections.

Re-exports§

pub use jni::matching;
pub use jni::ClassDecl;
pub use jni::ConstDecl;
pub use jni::DataClassDecl;
pub use jni::Declarations;
pub use jni::EnumClassDecl;
pub use jni::IgnoreDecl;
pub use jni::JniGen;
pub use jni::JniGenBuilder;
pub use jni::PackageDecl;
pub use jni::PtrClassDecl;
pub use jni::SealedClassDecl;
pub use jni::VariantDecl;

Modules§

jni
JNI back-end for the Registry pipeline.

Macros§

constant
Build a ConstDecl from a bare ident: constant!(MAX_LEN) is ConstDecl::new(prebindgen_registry::ident!(MAX_LEN)).
data_class
Build a DataClassDecl directly from a bare Rust type. See ptr_class!.
enum_class
Build an EnumClassDecl directly from a bare Rust type. See ptr_class!.
package
Build a PackageDecl directly: package!("model") is PackageDecl::new("model"); package!() (no args) is the base package (PackageDecl::new("")).
ptr_class
Build a PtrClassDecl directly from a bare Rust type: ptr_class!(Foo) is PtrClassDecl::new(<Foo as a parsed syn::Type>).
sealed_class
Build a SealedClassDecl directly from a bare Rust type. See ptr_class!.
variant
Build a VariantDecl from a bare variant ident, for SealedClassDecl::variant: variant!(PeriodicQueries).name("Periodic").

Structs§

CachedIfaceMethod
A (pinned interface class, method ID) pair resolved once per process. Declare as static; the embedded OnceLock handles the one-time resolution race (both winners produce equivalent values).
ConvertDecl
ConvertSourceDecl
One conversion source, accepted by ConvertDecl::input / ConvertDecl::output. Built by fun! — a #[prebindgen] conversion fn (bare ident, signature read from the registry) or a binding-local one (fun!(crate::f) + .sig(sig!(…)), the one vocabulary for locally defined callables; a Result<_, E> return states the error channel) — or by the direction-stating macros from! / try_from! / into! / try_into! (a core::convert trait conversion with a stated representation type).
ExpandParamDecl
Declares a type’s default input boundary: how a parameter of this type may be supplied, as a list of variants — “built from this constructor’s ingredients, OR that one’s, OR passed as an existing handle”. Applies to every function with a parameter of the type; a single function opts out or narrows via FunctionDecl::expand_param.
ExpandReturnDecl
Declares a type’s default output boundary: wherever the type is returned or handed to a callback, it is decomposed into this set of fields, all delivered in one FFI crossing — instead of an opaque handle the caller must then query field by field with more JNI calls. Applies to every function returning the type; a single function opts out or replaces the set via FunctionDecl::expand_return.
FieldsDecl
A value-form expansion: the accessor whose returned struct supplies the fields, plus the per-field adjustments. Built with fields! and handed to ExpandReturnDecl::fields.
FunctionDecl
Declares one #[prebindgen] function to export. The adapter either adds it to a package or attaches it to a class as a method or a factory.
KotlinFile
One Kotlin source file fragment: a package plus top-level declarations. Fragments of the same package are merged by super::file::merge_files.

Enums§

ExpandDecl
Unifies the two boundary decls into one type so an adapter’s expand can expose a single entry point — the boundary-decl peer of its class declarator. Deliberately no impl From<syn::Type> for ExpandDecl — a bare syn::Type alone doesn’t say which direction it describes, so every declaration names its direction via the matching constructor macro: .expand(prebindgen_registry::expand_param!(Summary)...), .expand(prebindgen_registry::expand_return!(Sample)...).
JniBindingError
Framework error type for the JNI binding’s error channel. T is the function’s domain error (() for the E-agnostic framework converters, whose failures are always Self::JniError).
WriteKotlinError
Errors surfaced by Kotlin emission.

Functions§

box_jboolean
Box a jni::sys::jboolean into java/lang/Boolean via cached valueOf.
box_jbyte
Box a jni::sys::jbyte into java/lang/Byte via cached valueOf.
box_jchar
Box a jni::sys::jchar into java/lang/Character via cached valueOf.
box_jdouble
Box a jni::sys::jdouble into java/lang/Double via cached valueOf.
box_jfloat
Box a jni::sys::jfloat into java/lang/Float via cached valueOf.
box_jint
Box a jni::sys::jint into java/lang/Integer via cached valueOf.
box_jlong
Box a jni::sys::jlong into java/lang/Long via cached valueOf.
box_jshort
Box a jni::sys::jshort into java/lang/Short via cached valueOf.
decode_byte_array
Converts a JNI JByteArray into a Rust Vec<u8>.
decode_string
Converts a JString into a Rust String.
encode_byte_array
Converts a Rust byte slice into a JNI JByteArray.
encode_string
Converts a Rust string-like value into a JNI JString.
null_byte_array
Returns a null JNI byte-array handle.
null_string
Returns a null JNI string handle.