Skip to content

Can JNI crate accept generics #437

Closed Answered by argv-minus-one
charleschege asked this question in Q&A
Discussion options

You must be logged in to vote

I don't think that's possible, no.

The Rust compiler generates (“instantiates”) a separate version of each generic function for each combination of type parameters it's called with. That happens at compile time. What you're writing there is a function that's dynamically looked up and called by the JVM after your Rust library is compiled, so there's no opportunity for that instantiation to happen.

I'm surprised that using #[no_mangle] on a function with type parameters isn't a compile error. That's arguably a bug in Rust, since such a function is impossible to call without name mangling.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@charleschege
Comment options

Answer selected by charleschege
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants