Good way to handle NifRresult (Ruslter) in gleam #3224
-
Hi, I am trying to around with interfacing Rustler and Gleam. One thing I noticed is, that it is not simple to handle a NifResult as a Result in Gleam. I have a function in Rust that returns a Nif Result. fn some_func() -> NifResult<String> {...} Using it as a Nif in erlang: -module(native)
-export([some_func/0])
-nifs([some_func/0])
some_func() ->
exit(nif_library_not_loaded). And using it in gleam: @external(erlang, "native", "some_fun")
pub fn some_func() -> Result(String, Dynamic) Trying round with this, like this: let assert Ok(val) = some_func() It seems to me, that this works for errors but not for "Ok" Values. Looking at some similar code in Elixir: https://github.com/elixir-nx/ortex/blob/main/lib/ortex/model.ex#L25 It seems to me (and I might be wrong), that I did not find any example, where a NifResult is used in Gleam and I am unsure how to do it. Can I even somehow represent a value, that can be Any advice on how to write a ffi when Returning Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Untagged unions are not representable in Gleam, you will need to call that function from Erlang and then convert it to a Gleam result. |
Beta Was this translation helpful? Give feedback.
Untagged unions are not representable in Gleam, you will need to call that function from Erlang and then convert it to a Gleam result.