-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin should use the builtin Result type #697
Comments
If the issue is things not implementing |
There's no reason not to use it other than the difficulty of making it throwable. I don't know how common Result usage is but I think it's nice to offer the user an idiomatic solution that doesn't require throwing. I tried introducing some types that made the return more rusty, but it seems antithetical to diplomat's philosophy. I'm going on a two week vacation tomorrow with intermittent rail travel so will be mostly away from the computer except during the longish train rides when I'll probably want to look at this to pass the time. @emarteca if you want to handle this faster, let me know, otherwise I'll see how far I can get on the trains. |
@jcrist1 do you mean the difficulty of making the error types throwable? because as I understand it Res doesn't need to be thrown, but I could be wrong |
@Manishearth |
@jcrist1 FFIError doesn't exist, but it could; it would be a type However we could also just add |
class FFIError<E>(val er: E): Throwable Yields
which is a bummer. But we could instead return a runtime exception with some runtime type info, e.g. data class FFIError(val errStr: String, val errType: String?) : Throwable("Received error $errStr of type $errType") {
companion object {
fun <E>fromE(err:E): FFIError {
return FFIError(err.toString(), err!!::class.simpleName)
}
}
} |
Ah, okay. Yeah let's just do that for now. I'll try and make the |
cc @jcrist1 @emarteca
Kotlin has a
Result<T>
(it's not aResult<T, E>
, but it still encapsulates a typedThrowable
error)Is there a reason we can't use it? We should use idiomatic stuff where possible. Is it idiomatic?
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/
The text was updated successfully, but these errors were encountered: