ARK-Builders / ark-core

The core of the ARK framework
MIT License
4 stars 3 forks source link

Investigate returning Kotlin style `Result` type through JNI bindings. #74

Open twitu opened 3 months ago

twitu commented 3 months ago

JNI does not support returning the generic types so Result<T> cannot be returned from bindings. JNI bindings can only return Java values. The solution implemented in #61 throws exception when a result type is an error. However, there might be a way to return Kotlin/functional style Result values from JNI bindings which will give a more ergonomic API.

Since JNI only allows Java types a Kotlin Result type is not supported directly. However, it is possible to create a Java Result class that mimics a Kotlin Result type.^1 To use this it will need to be defined and loaded into the JNIEnv^2 so that the Java Result object can be created and filled with the appropriate value.

The result will be a more ergonomic and functional style Java bindings to the fs-storage crate.