Benjamin-Philip
Having trouble with Rustler returning :ok (Erlang error: :invalid_struct:)
I’m having some trouble just returning ok from rust. The following fails with an Erlang error: :invalid_struct:
mod atoms {
rustler::atoms! {
ok
}
}
#[rustler::nif]
pub fn backend_deallocate(array: ExAf) -> Atom {
let exaf_array = array.resource.value();
match exaf_array {
ExAfArray::U8(a) => drop(a),
ExAfArray::U16(a) => drop(a),
ExAfArray::U32(a) => drop(a),
ExAfArray::U64(a) => drop(a),
ExAfArray::S16(a) => drop(a),
ExAfArray::S32(a) => drop(a),
ExAfArray::S64(a) => drop(a),
ExAfArray::F16(a) => drop(a),
ExAfArray::F32(a) => drop(a),
ExAfArray::F64(a) => drop(a),
ExAfArray::C64(a) => drop(a),
ExAfArray::C128(a) => drop(a),
}
atoms::ok()
}
How can I return :ok (or any other atom) from Rust?
Marked As Solved
Benjamin-Philip
Thanks for your reply @mindok!
It turns out the reason I was getting an Erlang Error: :invalid_struct error was because I was passing in an “invalid struct” (i.e. an incorrect input for my NIF) and not because of any issues with the rustler output.
Here’s what (in essence) worked for me:
#[rustler::nif]
pub fn ok() -> Atom {
atoms::ok()
}
5
Also Liked
mindok
I don’t really understand what I’m doing with Rustler, but this recipe seems to work (for me):
#[rustler::nif]
pub fn backend_deallocate(array: ExAf) -> Result<Atom> {
...
return Ok(atoms::ok());
}
2
SeokminHong
You can use rustler::types::atom module to use predefined atoms: nil, ok, error, true, and so on.
2
Popular in Questions
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Hello,
I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these
buyer = %{
id: ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New








