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:
prebindgen_registry::Registry::builderdescribes a binding over a model built from(syn::Item, SourceLocation)(typicallysource.items_all()).Registry::write_rustresolves every required type via a configuredJniGenBuilderand writes the generated Rust bindings file.JniGenBuilder::write_kotlinwalks the resolved registry to emit the secondary Kotlin artifacts (typed-handle classes, data/enum classes, exception classes, the centralizedJNINativeholder).
§Fixed-width unsigned integers
JniGenBuilder exposes Rust’s fixed-width unsigned scalars without narrowing their domain at the Kotlin boundary:
| Rust | Kotlin surface | JNI wire |
|---|---|---|
u8 | Int | jint |
u16 | Int | jint |
u32 | Long | jlong |
u64 | ULong | jlong / 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
ConstDeclfrom a bare ident:constant!(MAX_LEN)isConstDecl::new(prebindgen_registry::ident!(MAX_LEN)). - data_
class - Build a
DataClassDecldirectly from a bare Rust type. Seeptr_class!. - enum_
class - Build an
EnumClassDecldirectly from a bare Rust type. Seeptr_class!. - package
- Build a
PackageDecldirectly:package!("model")isPackageDecl::new("model");package!()(no args) is the base package (PackageDecl::new("")). - ptr_
class - Build a
PtrClassDecldirectly from a bare Rust type:ptr_class!(Foo)isPtrClassDecl::new(<Foo as a parsed syn::Type>). - sealed_
class - Build a
SealedClassDecldirectly from a bare Rust type. Seeptr_class!. - variant
- Build a
VariantDeclfrom a bare variant ident, forSealedClassDecl::variant:variant!(PeriodicQueries).name("Periodic").
Structs§
- Cached
Iface Method - A
(pinned interface class, method ID)pair resolved once per process. Declare asstatic; the embeddedOnceLockhandles the one-time resolution race (both winners produce equivalent values). - Convert
Decl - Convert
Source Decl - One conversion source, accepted by
ConvertDecl::input/ConvertDecl::output. Built byfun!— 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; aResult<_, E>return states the error channel) — or by the direction-stating macrosfrom!/try_from!/into!/try_into!(acore::converttrait conversion with a stated representation type). - Expand
Param Decl - 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. - Expand
Return Decl - 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. - Fields
Decl - A value-form expansion: the accessor whose returned struct supplies the
fields, plus the per-field adjustments. Built with
fields!and handed toExpandReturnDecl::fields. - Function
Decl - 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. - Kotlin
File - One Kotlin source file fragment: a package plus top-level declarations.
Fragments of the same package are merged by
super::file::merge_files.
Enums§
- Expand
Decl - Unifies the two boundary decls into one type so an adapter’s
expandcan expose a single entry point — the boundary-decl peer of its class declarator. Deliberately noimpl From<syn::Type> for ExpandDecl— a baresyn::Typealone 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)...). - JniBinding
Error - Framework error type for the JNI binding’s error channel.
Tis the function’s domain error (()for the E-agnostic framework converters, whose failures are alwaysSelf::JniError). - Write
Kotlin Error - Errors surfaced by Kotlin emission.
Functions§
- box_
jboolean - Box a
jni::sys::jbooleanintojava/lang/Booleanvia cachedvalueOf. - box_
jbyte - Box a
jni::sys::jbyteintojava/lang/Bytevia cachedvalueOf. - box_
jchar - Box a
jni::sys::jcharintojava/lang/Charactervia cachedvalueOf. - box_
jdouble - Box a
jni::sys::jdoubleintojava/lang/Doublevia cachedvalueOf. - box_
jfloat - Box a
jni::sys::jfloatintojava/lang/Floatvia cachedvalueOf. - box_
jint - Box a
jni::sys::jintintojava/lang/Integervia cachedvalueOf. - box_
jlong - Box a
jni::sys::jlongintojava/lang/Longvia cachedvalueOf. - box_
jshort - Box a
jni::sys::jshortintojava/lang/Shortvia cachedvalueOf. - decode_
byte_ array - Converts a JNI
JByteArrayinto a RustVec<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.