Benjamin-Philip
Generic Structs with Rustler
The Problem
I have the following structs:
pub struct ExAfRef<T: HasAfEnum>(pub RwLock<Array<T>>);
#[derive(NifStruct)]
#[module = "ExAF.Backend"]
pub struct ExAf<T>
where
T: HasAfEnum,
{
pub resource: ResourceArc<ExAfRef<T>>,
}
On compiling it passes the following the error:
error[E0107]: missing generics for struct `datatypes::ExAf`
--> src/datatypes.rs:10:12
|
10 | pub struct ExAf<T>
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `T`
--> src/datatypes.rs:10:12
|
10 | pub struct ExAf<T>
| ^^^^ -
help: add missing generic argument
|
10 | pub struct ExAf<T><T>
| ~~~~~~~
However when I comment out / remove the rustler specific bits, I don’t have the error:
pub struct ExAfRef<T: HasAfEnum>(pub RwLock<Array<T>>);
pub struct ExAf<T>
where
T: HasAfEnum,
{
pub resource: ExAfRef<T>,
}
How can I use generic structs with rustler?
What I am trying to do
I am writing some bindings to arrayfire using their rust crate. Their Array struct is typed and support multiple types like i64 and f64. I am trying to access references (and create references) to Arrays from Elixir. I figured that writing a struct with a trait bound to support all the various types would be the best way to do it.
If there is a better way of doing this without a generic struct, I would be happy to implement it.
Marked As Solved
SeokminHong
AFAIK, Rustler does not support generics for now.
1
Popular in Questions
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
can someone please explain to me how Enum.reduce works with maps
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
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
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217
Let’s say I have a map with required and optional k...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
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
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
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
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New







