uniffi-rs
uniffi-rs copied to clipboard
Return a Result<T, E> without throwing an error
This is more of a question. Is there any way to convert Result<T, E> into a swift Result? I really REALLY dislike exceptions, rust has taught me better ways. I don't need the error to be generic, ideally I would create a custom result type RResult<T> where the Err variant is always the same. Like this:
I know this doesn't work but it would basically be this.

Thanks in advance for any help!
┆Issue is synchronized with this Jira Task ┆Issue Number: UNIFFI-217
There's currently no built-in way to do that. You could have a wrapper on the Swift side that turns the value/exception back into a result.
There's currently no built-in way to do that. You could have a wrapper on the Swift side that turns the value/exception back into a result.
Thank you for the help!
You should stick with the paradigm of the language that you are using. Swift has first-class support for checked exceptions, and avoiding exceptions is just going to result in sub-par Swift code, simply because alternatives are not as well supported.
I'm running into the same issue with Kotlin code: people ask me if it's possible to return a Kotlin Result instead of a (possibly checked) exception.